Skip to content

Commit

Permalink
Android (#31)
Browse files Browse the repository at this point in the history
* android: fixes #25 (#29)

* android: fixes #26 (#30)

* android: fixes #33 (#37)

* android: fixes #33

* android: fixes #34 #35 #36

* android: move hardcoded strings to strings.xml and increase remote config fetch duration
  • Loading branch information
Roaim authored Jun 9, 2020
1 parent d29891f commit 340b8be
Show file tree
Hide file tree
Showing 23 changed files with 533 additions and 242 deletions.
7 changes: 4 additions & 3 deletions dtb-android/app/config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ext.appName = 'DTBazar'
ext.versionMajor = 1
ext.versionMinor = 1
ext.versionPatch = 5
ext.versionMinor = 35
ext.versionPatch = 36
ext.versionSuffix = ''
ext.vars = [
apiHost : 'API_HOST',
apiVersion : 'API_VERSION',
Expand All @@ -28,7 +29,7 @@ private Integer generateVersionCode() {

@SuppressWarnings("GrMethodMayBeStatic")
private String generateVersionName() {
return "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
return "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}${ext.versionSuffix}"
}

android {
Expand Down
22 changes: 21 additions & 1 deletion dtb-android/app/src/main/java/app/roaim/dtbazar/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import app.roaim.dtbazar.api.ApiUtils
import app.roaim.dtbazar.ui.ForceUpdateDialog
import app.roaim.dtbazar.utils.Loggable
import app.roaim.dtbazar.utils.log
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import javax.inject.Inject

class MainActivity : AppCompatActivity(), HasAndroidInjector {
class MainActivity : AppCompatActivity(), HasAndroidInjector, Loggable {

private lateinit var navController: NavController
private lateinit var appBarConfiguration: AppBarConfiguration
Expand Down Expand Up @@ -57,6 +63,20 @@ class MainActivity : AppCompatActivity(), HasAndroidInjector {
navView.visibility = View.VISIBLE
}
}

val remoteConfig = Firebase.remoteConfig
val remoteConfigSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 1800
}
remoteConfig.setConfigSettingsAsync(remoteConfigSettings)
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.fetchAndActivate().addOnCompleteListener {
log("RemoteConfig.Fetch: isSuccessful = ${it.isSuccessful}; result = ${it.result}")
}

if (remoteConfig.getBoolean("force_update")) {
ForceUpdateDialog().show(supportFragmentManager, null)
}
}

override fun onSupportNavigateUp(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ package app.roaim.dtbazar.ui
import android.content.Intent
import android.os.Bundle
import android.view.*
import android.widget.Toast
import androidx.fragment.app.Fragment
import app.roaim.dtbazar.BuildConfig
import app.roaim.dtbazar.R
import app.roaim.dtbazar.databinding.FragmentAboutBinding
import app.roaim.dtbazar.ui.store_details.AboutFragmentClickListener
import app.roaim.dtbazar.utils.openInCustomTab
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig


class AboutFragment : Fragment(), AboutFragmentClickListener {

companion object {
const val BASE_URL =
"${BuildConfig.API_HOST}${BuildConfig.API_ENDPOINT_PREFIX}${BuildConfig.API_VERSION}"
private var ossOpenedAt = 0L
}

private var _binding: FragmentAboutBinding? = null
Expand Down Expand Up @@ -45,7 +50,25 @@ class AboutFragment : Fragment(), AboutFragmentClickListener {
}

override fun onOssLicencesClick() {
startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java))
/*
we don't want firebase test lab's bot to enter into a 3rd party Activity
(which we don't have control over) and crash our app due to that libraries memory leak
*/
if (ossOpenedAt.plus(
Firebase.remoteConfig.getLong("oss_open_interval_second").times(1000)
) > System.currentTimeMillis()
) {
Toast.makeText(
requireContext(),
getString(R.string.toast_try_agin),
Toast.LENGTH_SHORT
).show()
return
}
startActivity(Intent(requireContext(), OssLicensesMenuActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
})
ossOpenedAt = System.currentTimeMillis()
}

override fun onTermsClick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app.roaim.dtbazar.ui

import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import app.roaim.dtbazar.R
import app.roaim.dtbazar.databinding.FragmentForceUpdateBinding
import app.roaim.dtbazar.utils.Loggable
import app.roaim.dtbazar.utils.log
import app.roaim.dtbazar.utils.navigateToPlayStore

class ForceUpdateDialog : DialogFragment(), View.OnClickListener, Loggable {

private var _binding: FragmentForceUpdateBinding? = null
private val binding get() = _binding!!

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
dialog?.window?.attributes?.windowAnimations = R.style.UpdateDialogAnimation
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentForceUpdateBinding.inflate(inflater, container, false)
binding.listener = this
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}

override fun onStart() {
super.onStart()
val matchParent = ViewGroup.LayoutParams.MATCH_PARENT
val wrapContent = ViewGroup.LayoutParams.MATCH_PARENT
dialog?.window?.setLayout(matchParent, wrapContent)
}

override fun onDestroyView() {
log("onDestroyView")
super.onDestroyView()
_binding = null
}

override fun onClick(v: View?) {
v?.navigateToPlayStore()
}

override fun onCancel(dialog: DialogInterface) {
super.onCancel(dialog)
requireActivity().finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.roaim.dtbazar.ui.login
import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
Expand All @@ -11,18 +12,23 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import app.roaim.dtbazar.R
import app.roaim.dtbazar.databinding.LoginFragmentBinding
import app.roaim.dtbazar.databinding.ViewInputDialogBinding
import app.roaim.dtbazar.di.Injectable
import app.roaim.dtbazar.model.Status
import app.roaim.dtbazar.ui.home.handleBackButtonEvent
import app.roaim.dtbazar.utils.Loggable
import app.roaim.dtbazar.utils.autoCleared
import app.roaim.dtbazar.utils.log
import app.roaim.dtbazar.utils.value
import com.facebook.AccessToken
import com.facebook.CallbackManager
import com.facebook.FacebookCallback
import com.facebook.FacebookException
import com.facebook.login.LoginManager
import com.facebook.login.LoginResult
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.get
import com.google.firebase.remoteconfig.ktx.remoteConfig
import javax.inject.Inject


Expand Down Expand Up @@ -85,6 +91,36 @@ class LoginFragment : Fragment(), Injectable, Loggable, FacebookCallback<LoginRe
}
it
}

createLoginWithFbAccessTokenFeature()
}

/**
* This is a hidden feature to bypass facebook login in robo test. It is enabled by tapping
* the version text for 11 times. This feature should only be enabled in alpha releases
*/
private fun createLoginWithFbAccessTokenFeature() {
var fbTokenInputDialogVisibiltyCountDown = 0
binding.textViewVersion.setOnClickListener {
if (fbTokenInputDialogVisibiltyCountDown < 10 ||
!Firebase.remoteConfig["enable_login_with_fb_access_token_feature"].asBoolean()
) {
fbTokenInputDialogVisibiltyCountDown = fbTokenInputDialogVisibiltyCountDown.inc()
return@setOnClickListener
}
val inputFbTokenBinding =
ViewInputDialogBinding.inflate(LayoutInflater.from(requireContext()))
AlertDialog.Builder(requireContext())
.setView(inputFbTokenBinding.root)
.setNegativeButton("Cancel", null)
.setPositiveButton("Submit") { _, _ ->
val fbAccessToken =
inputFbTokenBinding.editTextToken.value()
if (fbAccessToken.isNotEmpty()) onGetFacebookAccessToken(fbAccessToken)
}
.show()
fbTokenInputDialogVisibiltyCountDown = 0
}
}

private fun onGetFacebookAccessToken(facebookAccessToken: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FilterStoreDialog : DialogFragment(), Injectable, View.OnClickListener, Lo
override fun onStart() {
super.onStart()
val matchParent = ViewGroup.LayoutParams.MATCH_PARENT
val wrapContent = ViewGroup.LayoutParams.WRAP_CONTENT
val wrapContent = ViewGroup.LayoutParams.MATCH_PARENT
dialog?.window?.setLayout(matchParent, wrapContent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,17 @@ class PendingDonationFragment : Fragment(), Injectable, Loggable, ListItemClickL
val list = adapter.currentList.toMutableList()
list.remove(it.data)
adapter.submitList(list)
Toast.makeText(requireContext(), "Approved", Toast.LENGTH_SHORT).show()
Toast.makeText(
requireContext(),
getString(R.string.toast_approved),
Toast.LENGTH_SHORT
).show()
} else if (it.status == Status.FAILED) {
Toast.makeText(requireContext(), "Failed to Approve. ${it.msg}", Toast.LENGTH_LONG)
Toast.makeText(
requireContext(),
getString(R.string.toast_failed_to_approve, it.msg),
Toast.LENGTH_LONG
)
.show()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.widget.RadioGroup
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import app.roaim.dtbazar.BuildConfig
import app.roaim.dtbazar.R
import app.roaim.dtbazar.model.Food
import app.roaim.dtbazar.model.StoreFood
Expand Down Expand Up @@ -102,7 +103,17 @@ fun String.openInCustomTab(context: Context) {
CustomTabsIntent.Builder()
.setToolbarColor(context.getColorCompat(R.color.colorPrimary))
.build()
.launchUrl(context, Uri.parse(this))
.launchUrl(context, toUri())
}

fun View.navigateToPlayStore() {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(
"https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"
)
setPackage("com.android.vending")
}
context.startActivity(intent)
}

fun Context.getColorCompat(resId: Int): Int = ContextCompat.getColor(this, resId)
Loading

0 comments on commit 340b8be

Please sign in to comment.