Skip to content

Commit

Permalink
#17 in progress - facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
mjureczko committed May 18, 2024
1 parent d116c52 commit 8e002cc
Show file tree
Hide file tree
Showing 32 changed files with 608 additions and 128 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
TODO:
- add screens titles
-- on searching screen title show which treasure is being searched
-
- add all translations
- w introduction dodać widok-instrukcję z kodem QR
- kopiowanie "assetów" podczas wyświetlania splash screen
- remove dead code
- do not show splash when switching back to app
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ fun CommemorativeScreen(
navController: NavController,
navBackStackEntry: NavBackStackEntry,
onClickOnGuide: () -> Unit,
goToFacebook: () -> Unit,
) {
val scaffoldState: ScaffoldState = rememberScaffoldState()
Scaffold(
scaffoldState = scaffoldState,
topBar = { TopBar(navController, onClickOnGuide) },
topBar = { TopBar(navController, onClickOnGuide, goToFacebook) },
content = {
CommemorativeScreenBody(
navController,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pl.marianjureczko.poszukiwacz.activity.facebook

class ElementDescription(
//TODO: change var to val to avoid missing compose refreshes
data class ElementDescription(
val index: Int,
var type: Type,
var isSelected: Boolean,
val description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress
import pl.marianjureczko.poszukiwacz.shared.StorageHelper

class FacebookViewModel(private val state: SavedStateHandle) : ViewModel() {
class FacebookViewModel(private val state: SavedStateHandle) : FacebookReportModel, ViewModel() {
private val TAG = javaClass.simpleName
lateinit var progress: TreasuresProgress
override lateinit var progress: TreasuresProgress
private set
var hunterPath: HunterPath? = null
override var hunterPath: HunterPath? = null
private set
lateinit var elements: List<ElementDescription>
private set

lateinit var route: Route
override lateinit var route: Route

fun initialize(context: Context, hunterPath: HunterPath?, progress: TreasuresProgress) {
this.progress = progress
this.hunterPath = hunterPath
val elements = mutableListOf<ElementDescription>()
elements.add(ElementDescription(Type.TREASURES_SUMMARY, true, context.getString(R.string.collected_treasures)))
elements.add(ElementDescription(0, Type.TREASURES_SUMMARY, true, context.getString(R.string.collected_treasures)))
val treasure = context.getString(R.string.treasure)
progress.commemorativePhotosByTreasuresDescriptionIds.forEach { (id, photo) ->
elements.add(ElementDescription(Type.COMMEMORATIVE_PHOTO, true, "$treasure $id", orderNumber = id, photo = photo))
elements.add(ElementDescription(0, Type.COMMEMORATIVE_PHOTO, true, "$treasure $id", orderNumber = id, photo = photo))
}
elements.add(ElementDescription(Type.MAP, true, context.getString(R.string.treasures_map)))
elements.add(ElementDescription(Type.MAP_ROUTE, true, context.getString(R.string.route_on_map)))
elements.add(ElementDescription(Type.MAP_SUMMARY, true, context.getString(R.string.treasures_map_summary)))
elements.add(ElementDescription(0, Type.MAP, true, context.getString(R.string.treasures_map)))
elements.add(ElementDescription(0, Type.MAP_ROUTE, true, context.getString(R.string.route_on_map)))
elements.add(ElementDescription(0, Type.MAP_SUMMARY, true, context.getString(R.string.treasures_map_summary)))
this.route = StorageHelper(context).loadRoute(progress.routeName)
this.elements = elements
}
Expand All @@ -40,13 +40,13 @@ class FacebookViewModel(private val state: SavedStateHandle) : ViewModel() {

fun getElementsCount(): Int = elements.size

fun getSummaryElement(): ElementDescription = elements[0]
override fun getSummaryElement(): ElementDescription = elements[0]

fun getCommemorativePhotoElements(): List<ElementDescription> = elements.filter { it.type == Type.COMMEMORATIVE_PHOTO }
override fun getCommemorativePhotoElements(): List<ElementDescription> = elements.filter { it.type == Type.COMMEMORATIVE_PHOTO }

fun getMap(): ElementDescription? = elements.find { it.type == Type.MAP }
override fun getMap(): ElementDescription? = elements.find { it.type == Type.MAP }

fun getMapRoute(): ElementDescription? = elements.find { it.type == Type.MAP_ROUTE }
override fun getMapRoute(): ElementDescription? = elements.find { it.type == Type.MAP_ROUTE }

fun getMapSummary(): ElementDescription? = elements.find { it.type == Type.MAP_SUMMARY }
override fun getMapSummary(): ElementDescription? = elements.find { it.type == Type.MAP_SUMMARY }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlin.math.min
import kotlin.random.Random

class ReportCommemorativePhotos(
model: FacebookViewModel,
model: FacebookReportModel,
private val font: Typeface,
rotationSeed: Long = currentTimeMillis()
) : ReportPart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import androidx.core.content.res.ResourcesCompat
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.model.HunterPath
import pl.marianjureczko.poszukiwacz.model.Route
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress
import java.util.Collections

interface ReportPart {
fun height(): Float
}

interface FacebookReportModel {
fun getSummaryElement(): ElementDescription
fun getCommemorativePhotoElements(): List<ElementDescription>
fun getMap(): ElementDescription?
fun getMapSummary(): ElementDescription?
fun getMapRoute(): ElementDescription?

val hunterPath: HunterPath?
val route: Route
val progress: TreasuresProgress
}

class ReportGenerator {
/**
* @return it is returned for testing purposes
*/
fun create(context: Context, model: FacebookViewModel, reportPublisher: (Bitmap) -> Unit): Bitmap {
fun create(context: Context, model: FacebookReportModel, reportPublisher: (Bitmap) -> Unit): Bitmap {
val typeface = ResourcesCompat.getFont(context, R.font.akaya_telivigala)!!
val title = ReportTitle(model, typeface)
val summary = ReportSummary(model, typeface)
Expand All @@ -24,7 +39,8 @@ class ReportGenerator {
val map = ReportMap(model)
val mapSummary = ReportMapSummary(model, typeface)
val footer = ReportFooter()
val height = title.height() + summary.height() + commemorativePhotos.height() + mapHeader.height() + map.height() + mapSummary.height() + footer.height()
val height =
title.height() + summary.height() + commemorativePhotos.height() + mapHeader.height() + map.height() + mapSummary.height() + footer.height()
val bitmap = Bitmap.createBitmap(ReportCommons.REPORT_WIDTH, height.toInt(), Bitmap.Config.ARGB_8888)

val canvas = Canvas(bitmap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import pl.marianjureczko.poszukiwacz.model.TreasuresProgress


class ReportMap(
private val model: FacebookViewModel
private val model: FacebookReportModel
) : ReportPart {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.graphics.Typeface
import pl.marianjureczko.poszukiwacz.R

class ReportMapHeader(
private val model: FacebookViewModel,
private val model: FacebookReportModel,
private val font: Typeface
) : ReportPart {
override fun height(): Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.text.DateFormat
import java.util.Locale

class ReportMapSummary(
private val model: FacebookViewModel,
private val model: FacebookReportModel,
private val font: Typeface
) : ReportPart {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress

class ReportSummary(
private val model: FacebookViewModel,
private val model: FacebookReportModel,
private val font: Typeface
) : ReportPart {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package pl.marianjureczko.poszukiwacz.activity.facebook

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Typeface
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.model.TreasuresProgress

class ReportTitle(
private val model: FacebookViewModel,
private val model: FacebookReportModel,
private val font: Typeface
) : ReportPart {
override fun height(): Float = 150f
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pl.marianjureczko.poszukiwacz.activity.facebook.n

import android.content.Context
import android.content.pm.PackageManager
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavHostController
import pl.marianjureczko.poszukiwacz.R
import pl.marianjureczko.poszukiwacz.activity.main.FACEBOOK_PATH

object FacebookHelper {
private const val facebookPackage = "com.facebook.katana"
@Composable
fun createFacebookCallback(navController: NavHostController): () -> Unit {
val context = LocalContext.current
val noFacebookErrorMsg = stringResource(id = R.string.facebook_share_impossible)
val goToFacebook = {
// if (isFacebookInstalled(context)) {
navController.navigate(FACEBOOK_PATH)
// } else {
// Toast.makeText(App.getAppContext(), noFacebookErrorMsg, Toast.LENGTH_LONG).show()
// }
}
return goToFacebook
}

private fun isFacebookInstalled(context: Context): Boolean {
val packageManager = context.packageManager
return try {
//the not deprecated version requires API 33
packageManager.getPackageInfo(facebookPackage, PackageManager.GET_ACTIVITIES)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}
}
Loading

0 comments on commit 8e002cc

Please sign in to comment.