diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index c73509ca..afe23c3c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -58,7 +58,7 @@ import pl.szczodrzynski.edziennik.ui.modules.feedback.FeedbackFragment import pl.szczodrzynski.edziennik.ui.modules.feedback.HelpFragment import pl.szczodrzynski.edziennik.ui.modules.grades.GradesFragment import pl.szczodrzynski.edziennik.ui.modules.grades.editor.GradesEditorFragment -import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentV2 +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment import pl.szczodrzynski.edziennik.ui.modules.homework.HomeworkFragment import pl.szczodrzynski.edziennik.ui.modules.login.LoginActivity import pl.szczodrzynski.edziennik.ui.modules.messages.MessageFragment @@ -127,7 +127,7 @@ class MainActivity : AppCompatActivity() { val list: MutableList = mutableListOf() // home item - list += NavTarget(DRAWER_ITEM_HOME, R.string.menu_home_page, HomeFragmentV2::class) + list += NavTarget(DRAWER_ITEM_HOME, R.string.menu_home_page, HomeFragment::class) .withTitle(R.string.app_name) .withIcon(CommunityMaterial.Icon2.cmd_home_outline) .isInDrawer(true) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt index 070fb19c..62c6b1ee 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt @@ -7,7 +7,7 @@ package pl.szczodrzynski.edziennik.ui.modules.home import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.RecyclerView import com.google.android.material.card.MaterialCardView -import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentV2.Companion.swapCards +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.Companion.swapCards import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator class CardItemTouchHelperCallback(private val cardAdapter: HomeCardAdapter, private val refreshLayout: SwipeRefreshLayoutNoIndicator?) : ItemTouchHelper.Callback() { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt index e349033d..59efd786 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt @@ -28,6 +28,7 @@ import pl.szczodrzynski.edziennik.MainActivity import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding import pl.szczodrzynski.edziennik.ui.dialogs.home.StudentNumberDialog +import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeDebugCard import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeGradesCard import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeLuckyNumberCard import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeTimetableCard @@ -36,9 +37,9 @@ import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem import kotlin.coroutines.CoroutineContext -class HomeFragmentV2 : Fragment(), CoroutineScope { +class HomeFragment : Fragment(), CoroutineScope { companion object { - private const val TAG = "HomeFragmentOld" + private const val TAG = "HomeFragment" fun swapCards(fromPosition: Int, toPosition: Int, cardAdapter: HomeCardAdapter) { val homeCards = App.getConfig().ui.homeCards.toMutableList() @@ -121,6 +122,8 @@ class HomeFragmentV2 : Fragment(), CoroutineScope { else -> null } } + if (App.devMode) + items += HomeDebugCard(100, app, activity, this, app.profile) val adapter = HomeCardAdapter(items) val itemTouchHelper = ItemTouchHelper(CardItemTouchHelperCallback(adapter, b.refreshLayout)) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeDebugCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeDebugCard.kt new file mode 100644 index 00000000..68416d0d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeDebugCard.kt @@ -0,0 +1,92 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-12-22. + */ + +package pl.szczodrzynski.edziennik.ui.modules.home.cards + +import android.content.Intent +import android.net.Uri +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.FrameLayout +import androidx.core.view.plusAssign +import androidx.core.view.setMargins +import androidx.work.WorkManager +import com.chuckerteam.chucker.api.Chucker +import com.hypertrack.hyperlog.HyperLog +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile +import pl.szczodrzynski.edziennik.databinding.CardHomeDebugBinding +import pl.szczodrzynski.edziennik.dp +import pl.szczodrzynski.edziennik.onClick +import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard +import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment +import pl.szczodrzynski.edziennik.ui.modules.login.LoginLibrusCaptchaActivity +import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeActivity +import kotlin.coroutines.CoroutineContext + +class HomeDebugCard( + override val id: Int, + val app: App, + val activity: MainActivity, + val fragment: HomeFragment, + val profile: Profile +) : HomeCard, CoroutineScope { + companion object { + private const val TAG = "HomeDebugCard" + } + + private var job: Job = Job() + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + + override fun bind(position: Int, holder: HomeCardAdapter.ViewHolder) { launch { + holder.root.removeAllViews() + val b = CardHomeDebugBinding.inflate(LayoutInflater.from(holder.root.context)) + b.root.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { + setMargins(8.dp) + } + holder.root += b.root + + b.composeButton.onClick { + app.startActivity(Intent(activity, MessagesComposeActivity::class.java)); + } + + b.pruneWorkButton.onClick { + WorkManager.getInstance(app).pruneWork() + } + + b.runChucker.onClick { + app.startActivity(Chucker.getLaunchIntent(activity, 1)); + } + + b.librusCaptchaButton.onClick { + app.startActivity(Intent(activity, LoginLibrusCaptchaActivity::class.java)) + } + + b.getLogs.onClick { + val logs = HyperLog.getDeviceLogsInFile(activity, true) + val intent = Intent(Intent.ACTION_SEND) + + if (logs.exists()) { + intent.type = "text/plain" + intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + logs.absolutePath)) + intent.putExtra(Intent.EXTRA_SUBJECT, "Share debug logs") + intent.putExtra(Intent.EXTRA_TEXT, "Share debug logs") + app.startActivity(Intent.createChooser(intent, "Share debug logs")) + } + } + + holder.root.onClick { + // do stuff + } + }} + + override fun unbind(position: Int, holder: HomeCardAdapter.ViewHolder) = Unit +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeGradesCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeGradesCard.kt index 4dd55615..8d5a5fc5 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeGradesCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeGradesCard.kt @@ -36,7 +36,7 @@ import pl.szczodrzynski.edziennik.databinding.CardHomeGradesBinding import pl.szczodrzynski.edziennik.dp import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter -import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentV2 +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment import pl.szczodrzynski.edziennik.utils.Colors import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.models.ItemGradesSubjectModel @@ -46,7 +46,7 @@ class HomeGradesCard( override val id: Int, val app: App, val activity: MainActivity, - val fragment: HomeFragmentV2, + val fragment: HomeFragment, val profile: Profile ) : HomeCard, CoroutineScope { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt index 652db015..13d5580b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt @@ -21,7 +21,7 @@ import pl.szczodrzynski.edziennik.databinding.CardHomeLuckyNumberBinding import pl.szczodrzynski.edziennik.ui.dialogs.home.StudentNumberDialog import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter -import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentV2 +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment import pl.szczodrzynski.edziennik.utils.models.Date import kotlin.coroutines.CoroutineContext @@ -29,7 +29,7 @@ class HomeLuckyNumberCard( override val id: Int, val app: App, val activity: MainActivity, - val fragment: HomeFragmentV2, + val fragment: HomeFragment, val profile: Profile ) : HomeCard, CoroutineScope { companion object { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTemplateCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTemplateCard.kt new file mode 100644 index 00000000..9741b956 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTemplateCard.kt @@ -0,0 +1,58 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-12-22. + */ + +package pl.szczodrzynski.edziennik.ui.modules.home.cards + +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.FrameLayout +import androidx.core.view.plusAssign +import androidx.core.view.setMargins +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile +import pl.szczodrzynski.edziennik.databinding.CardHomeTemplateBinding +import pl.szczodrzynski.edziennik.dp +import pl.szczodrzynski.edziennik.onClick +import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard +import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment +import kotlin.coroutines.CoroutineContext + +class HomeTemplateCard( + override val id: Int, + val app: App, + val activity: MainActivity, + val fragment: HomeFragment, + val profile: Profile +) : HomeCard, CoroutineScope { + companion object { + private const val TAG = "HomeTemplateCard" + } + + private var job: Job = Job() + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + + override fun bind(position: Int, holder: HomeCardAdapter.ViewHolder) { launch { + holder.root.removeAllViews() + val b = CardHomeTemplateBinding.inflate(LayoutInflater.from(holder.root.context)) + b.root.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { + setMargins(8.dp) + } + holder.root += b.root + + // do stuff + + holder.root.onClick { + // do stuff + } + }} + + override fun unbind(position: Int, holder: HomeCardAdapter.ViewHolder) = Unit +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt index fa8ca378..1c266e30 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt @@ -32,7 +32,7 @@ import pl.szczodrzynski.edziennik.databinding.CardHomeTimetableBinding import pl.szczodrzynski.edziennik.ui.dialogs.bell.BellSyncTimeChooseDialog import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter -import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentV2 +import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Time import pl.szczodrzynski.edziennik.utils.models.Week @@ -43,7 +43,7 @@ class HomeTimetableCard( override val id: Int, val app: App, val activity: MainActivity, - val fragment: HomeFragmentV2, + val fragment: HomeFragment, val profile: Profile ) : HomeCard, CoroutineScope { companion object { diff --git a/app/src/main/res/layout/card_home_debug.xml b/app/src/main/res/layout/card_home_debug.xml new file mode 100644 index 00000000..9346482b --- /dev/null +++ b/app/src/main/res/layout/card_home_debug.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/card_home_template.xml b/app/src/main/res/layout/card_home_template.xml new file mode 100644 index 00000000..bf8f8874 --- /dev/null +++ b/app/src/main/res/layout/card_home_template.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + \ No newline at end of file