From 40a3a9ba26152d363b4863ddf4d338663d80e847 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Thu, 29 Aug 2024 18:17:10 +0200 Subject: [PATCH] Start tutorial --- app/build.gradle | 3 + .../org/pixeldroid/app/main/MainActivity.kt | 6 ++ .../app/settings/SettingsActivity.kt | 2 + .../app/settings/TutorialSettingsDialog.kt | 67 +++++++++++++++++++ app/src/main/res/drawable/help.xml | 5 ++ .../main/res/drawable/ic_home_white_24dp.xml | 4 +- app/src/main/res/drawable/notifications.xml | 4 +- app/src/main/res/drawable/photo_camera.xml | 4 +- app/src/main/res/values/strings.xml | 5 ++ app/src/main/res/xml/root_preferences.xml | 5 ++ pixel_common | 2 +- 11 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/org/pixeldroid/app/settings/TutorialSettingsDialog.kt create mode 100644 app/src/main/res/drawable/help.xml diff --git a/app/build.gradle b/app/build.gradle index d383d43e..b6e6847c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -226,6 +226,9 @@ dependencies { implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0' + //Interactive tutorial + implementation 'com.getkeepsafe.taptargetview:taptargetview:1.14.0' + implementation 'com.google.android.material:material:1.12.0' //Dagger (dependency injection) diff --git a/app/src/main/java/org/pixeldroid/app/main/MainActivity.kt b/app/src/main/java/org/pixeldroid/app/main/MainActivity.kt index 3c882e5c..7c697ead 100644 --- a/app/src/main/java/org/pixeldroid/app/main/MainActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/main/MainActivity.kt @@ -66,6 +66,7 @@ import org.pixeldroid.app.posts.feeds.uncachedFeeds.UncachedPostsFragment import org.pixeldroid.app.profile.ProfileActivity import org.pixeldroid.app.searchDiscover.SearchDiscoverFragment import org.pixeldroid.app.settings.SettingsActivity +import org.pixeldroid.app.settings.TutorialSettingsDialog.Companion.START_TUTORIAL import org.pixeldroid.app.utils.BaseActivity import org.pixeldroid.app.utils.Tab import org.pixeldroid.app.utils.api.objects.Notification @@ -128,9 +129,14 @@ class MainActivity : BaseActivity() { val showNotification: Boolean = intent.getBooleanExtra(SHOW_NOTIFICATION_TAG, false) + val showTutorial: Int = intent.getIntExtra(START_TUTORIAL, -1) + if(showNotification){ binding.viewPager.currentItem = 3 + } else if(showTutorial > 0) { + } + if (ActivityCompat.checkSelfPermission(applicationContext, Manifest.permission.POST_NOTIFICATIONS ) == PackageManager.PERMISSION_GRANTED diff --git a/app/src/main/java/org/pixeldroid/app/settings/SettingsActivity.kt b/app/src/main/java/org/pixeldroid/app/settings/SettingsActivity.kt index a4baff4f..be149b3e 100644 --- a/app/src/main/java/org/pixeldroid/app/settings/SettingsActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/settings/SettingsActivity.kt @@ -107,6 +107,8 @@ class SettingsActivity : ThemedActivity(), SharedPreferences.OnSharedPreferenceC dialogFragment = LanguageSettingFragment() } else if (preference.key == "arrange_tabs") { dialogFragment = ArrangeTabsFragment() + } else if (preference.key == "tutorial") { + dialogFragment = TutorialSettingsDialog() } if (dialogFragment != null) { dialogFragment.setTargetFragment(this, 0) diff --git a/app/src/main/java/org/pixeldroid/app/settings/TutorialSettingsDialog.kt b/app/src/main/java/org/pixeldroid/app/settings/TutorialSettingsDialog.kt new file mode 100644 index 00000000..4b93c572 --- /dev/null +++ b/app/src/main/java/org/pixeldroid/app/settings/TutorialSettingsDialog.kt @@ -0,0 +1,67 @@ +package org.pixeldroid.app.settings; + +import android.app.Dialog +import android.content.Context +import android.content.Intent +import android.graphics.Typeface +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import android.widget.TextView +import androidx.fragment.app.DialogFragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.pixeldroid.app.R +import org.pixeldroid.app.main.MainActivity + +class TutorialSettingsDialog: DialogFragment() { + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val items = arrayOf( + Pair(R.string.feeds_tutorial, R.drawable.ic_home_white_24dp), + Pair(R.string.create_tutorial, R.drawable.photo_camera), + Pair(R.string.feeds_tutorial, R.drawable.notifications), + Pair(R.string.feeds_tutorial, R.drawable.outline_bottom_navigation) + ) + + val adapter = object : ArrayAdapter>(requireContext(), android.R.layout.simple_list_item_1, items) { + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + + val view: TextView = if (convertView == null) { + LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, parent, false) as TextView + } else { + convertView as TextView + } + + val item = getItem(position) + + if (item != null) { + view.setText(item.first) + view.setTypeface(null, Typeface.NORMAL) // Set the typeface to normal + view.setCompoundDrawablesWithIntrinsicBounds(item.second, 0, 0, 0) + view.compoundDrawablePadding = 16 // Add padding between text and drawable + } + + view.setPadding(0, 32, 0, 32) + return view + } + } + return MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.tutorial_choice)) + .setAdapter(adapter) { _, which -> + val intent = Intent(requireContext(), MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + intent.putExtra(START_TUTORIAL, which) + startActivity(intent) + } + .setNegativeButton(android.R.string.cancel) { dialog, _ -> + dialog.dismiss() + } + .create() + } + + companion object { + const val START_TUTORIAL = "tutorial_start_intent" + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/help.xml b/app/src/main/res/drawable/help.xml new file mode 100644 index 00000000..d1266fe9 --- /dev/null +++ b/app/src/main/res/drawable/help.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_home_white_24dp.xml b/app/src/main/res/drawable/ic_home_white_24dp.xml index 884766cc..ce574948 100644 --- a/app/src/main/res/drawable/ic_home_white_24dp.xml +++ b/app/src/main/res/drawable/ic_home_white_24dp.xml @@ -1,5 +1,5 @@ - - + \ No newline at end of file diff --git a/app/src/main/res/drawable/notifications.xml b/app/src/main/res/drawable/notifications.xml index 538f5818..f285f95e 100644 --- a/app/src/main/res/drawable/notifications.xml +++ b/app/src/main/res/drawable/notifications.xml @@ -1,5 +1,5 @@ - - + diff --git a/app/src/main/res/drawable/photo_camera.xml b/app/src/main/res/drawable/photo_camera.xml index 3e0e2d46..a2d0678a 100644 --- a/app/src/main/res/drawable/photo_camera.xml +++ b/app/src/main/res/drawable/photo_camera.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 971f0253..e6c03fdf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -361,4 +361,9 @@ For more info about Pixelfed, you can check here: https://pixelfed.org" Target username Message you want to write. Say hello! Error sending your message! Check the username + Tutorial + Explanations on how to use PixelDroid and Pixelfed + Feeds, how do they work? Where do they come from? + A little walk through creating posts + What could you use some help with? diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 346a5135..7355e284 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -54,6 +54,11 @@ +