-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Implemented Forem app popup on start * Added bottom bar options * Improved UX * Deep-linking finished * Icon updates
- Loading branch information
Showing
15 changed files
with
647 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
app/src/main/java/to/dev/dev_android/activities/ForemAppDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package to.dev.dev_android.activities | ||
|
||
import android.app.Activity | ||
import android.content.ActivityNotFoundException | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.fragment.app.DialogFragment | ||
import android.content.pm.PackageManager | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import to.dev.dev_android.R | ||
|
||
class ForemAppDialog : DialogFragment() { | ||
|
||
companion object { | ||
const val PACKAGE_NAME = "com.forem.android" | ||
private const val FOREM_URL = "ForemAppDialog.url" | ||
|
||
fun newInstance(url: String): ForemAppDialog { | ||
val foremAppDialog = ForemAppDialog() | ||
val args = Bundle() | ||
args.putString(FOREM_URL, url) | ||
foremAppDialog.arguments = args | ||
return foremAppDialog | ||
} | ||
|
||
fun isForemAppAlreadyInstalled(activity: Activity?): Boolean { | ||
return try { | ||
activity?.packageManager?.getPackageInfo(PACKAGE_NAME, 0) | ||
true | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
false | ||
} | ||
} | ||
|
||
fun openForemApp(activity: Activity?, url: String?) { | ||
val packageManager: PackageManager? = activity?.packageManager | ||
val app = packageManager?.getLaunchIntentForPackage(PACKAGE_NAME) | ||
if (!url.isNullOrEmpty()) { | ||
app?.putExtra(Intent.EXTRA_TEXT, url) | ||
} | ||
activity?.startActivity(app) | ||
} | ||
} | ||
|
||
lateinit var url: String | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
val width = resources.displayMetrics.widthPixels | ||
dialog!!.window?.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
val args = arguments | ||
url = args?.getString(FOREM_URL) ?: "" | ||
|
||
val view = inflater.inflate(R.layout.forem_app_dialog, container, false) | ||
if (dialog != null && dialog!!.window != null) { | ||
dialog!!.window?.setBackgroundDrawableResource(R.drawable.forem_dialog_fragment_background) | ||
} | ||
val downloadInstallForemAppTextView = | ||
view.findViewById<TextView>(R.id.download_install_forem_app_text_view) | ||
val downloadOpenForemAppImageView = | ||
view.findViewById<ImageView>(R.id.download_open_forem_image_view) | ||
val descriptionTextView = | ||
view.findViewById<TextView>(R.id.forem_app_dialog_description_text_view) | ||
|
||
if (isForemAppAlreadyInstalled(activity)) { | ||
downloadInstallForemAppTextView.text = getString(R.string.open_forem_app) | ||
downloadOpenForemAppImageView.setImageDrawable( | ||
ContextCompat.getDrawable( | ||
this.requireContext(), | ||
R.drawable.ic_compass | ||
) | ||
) | ||
descriptionTextView.text = getString(R.string.forem_app_dialog_description_if_installed) | ||
} else { | ||
downloadInstallForemAppTextView.text = getString(R.string.download_forem_app) | ||
downloadOpenForemAppImageView.setImageDrawable( | ||
ContextCompat.getDrawable( | ||
this.requireContext(), | ||
R.drawable.ic_baseline_arrow_downward_24 | ||
) | ||
) | ||
descriptionTextView.text = getString(R.string.forem_app_dialog_description) | ||
} | ||
|
||
val downloadLayout = view.findViewById<ConstraintLayout>(R.id.download_forem_app_layout) | ||
|
||
downloadLayout.setOnClickListener { | ||
openForemAppLink() | ||
} | ||
return view | ||
} | ||
|
||
private fun openForemAppLink() { | ||
if (isForemAppAlreadyInstalled(activity)) { | ||
openForemApp(activity, url) | ||
} else { | ||
try { | ||
// Opens Forem app in Play Store, if Play Store app is available. | ||
activity?.startActivity( | ||
Intent( | ||
Intent.ACTION_VIEW, | ||
Uri.parse("market://details?id=$PACKAGE_NAME") | ||
) | ||
) | ||
} catch (e: ActivityNotFoundException) { | ||
// Opens Forem app on Play Store in browser. | ||
activity?.startActivity( | ||
Intent( | ||
Intent.ACTION_VIEW, | ||
Uri.parse("https://play.google.com/store/apps/details?id=$PACKAGE_NAME") | ||
) | ||
) | ||
} | ||
} | ||
this.dismiss() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/res/drawable/forem_dialog_fragment_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<inset xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:drawable="@drawable/rounded_dialog" | ||
android:insetLeft="16dp" | ||
android:insetRight="16dp" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="28" | ||
android:viewportHeight="28"> | ||
<path | ||
android:pathData="M13.987,28C6.274,28 0,21.714 0,13.987 0,6.275 6.274,0 13.987,0 21.714,0 28,6.275 28,13.987 28,21.714 21.714,28 13.987,28zM13.987,1C6.826,1 1,6.826 1,13.987 1,21.163 6.826,27 13.987,27 21.162,27 27,21.163 27,13.987 27,6.826 21.162,1 13.987,1z" | ||
android:fillColor="#0c0c0c"/> | ||
<path | ||
android:pathData="M6.821,21.179l4.922,-9.436 9.436,-4.923 -4.922,9.436 -9.436,4.923zM12.484,12.485l-3.306,6.336 6.337,-3.306 3.306,-6.336 -6.337,3.306z" | ||
android:fillColor="#0c0c0c"/> | ||
<path | ||
android:pathData="M14,15.499c-0.384,0 -0.769,-0.146 -1.061,-0.438a1.501,1.501 0,0 1,0 -2.121,1.501 1.501,0 0,1 2.121,0 1.501,1.501 0,0 1,0 2.121,1.494 1.494,0 0,1 -1.06,0.438zM14,13.5a0.498,0.498 0,0 0,-0.354 0.853A0.5,0.5 0,1 0,14 13.5z" | ||
android:fillColor="#0c0c0c"/> | ||
</vector> |
Oops, something went wrong.