Skip to content

Commit

Permalink
Merge pull request #200 from jakepurple13/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jakepurple13 authored Sep 1, 2021
2 parents a513520 + b61cfa4 commit bd35c1d
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class DetailsFragment : Fragment() {
imageModel = model.imageUrl,
contentDescription = null,
contentScale = ContentScale.None,
requestBuilder = Glide.with(LocalView.current).asBitmap().transform(RoundedCorners(5)),
requestBuilder = Glide.with(LocalView.current).asDrawable().transform(RoundedCorners(5)),
modifier = Modifier
.scaleRotateOffset()
.defaultMinSize(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
Expand All @@ -350,7 +350,6 @@ class DetailsFragment : Fragment() {
imageModel = model.imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current).asBitmap(),
modifier = Modifier.matchParentSize()
)

Expand Down Expand Up @@ -385,10 +384,7 @@ class DetailsFragment : Fragment() {
imageModel = model.imageUrl,
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
//.override(360, 480)
.transform(RoundedCorners(5)),
requestBuilder = Glide.with(LocalView.current).asDrawable().transform(RoundedCorners(5)),
error = logo,
placeHolder = logo,
bitmapPalette = BitmapPalette { p ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class GlobalSearchFragment : Fragment() {
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
//.override(360, 480)
.placeholder(placeHolder)
.error(error)
Expand Down
151 changes: 125 additions & 26 deletions UIViews/src/main/java/com/programmersbox/uiviews/NotificationFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
Expand All @@ -30,7 +34,6 @@ import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.google.android.material.composethemeadapter.MdcTheme
import com.programmersbox.favoritesdatabase.ItemDatabase
Expand Down Expand Up @@ -104,7 +107,7 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {
contentDescription = "",
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
.override(360, 480)
.thumbnail(0.5f)
.transform(GranularRoundedCorners(0f, 15f, 15f, 0f)),
Expand All @@ -127,18 +130,18 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {
Text(item.notiTitle)
Text(item.source)
}

}
}
) {
Column(
) { p ->
LazyColumn(contentPadding = p) { items(items) { NotificationItem(item = it, navController = findNavController()) } }
/*Column(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
StaggeredVerticalGrid(
columns = 2,
modifier = Modifier.padding(it)
) { items.forEach { NotificationItem(it, findNavController()) } }
}
}*/
}

}
Expand Down Expand Up @@ -199,23 +202,117 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {

}

Card(
onClick = {
genericInfo.toSource(item.source)?.getSourceByUrl(item.url)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribeBy { navController.navigate(NotificationFragmentDirections.actionNotificationFragmentToDetailsFragment(it)) }
?.addTo(disposable)
},
elevation = 5.dp,
indication = rememberRipple(),
onClickLabel = item.notiTitle,
modifier = Modifier
.padding(5.dp)
.fadeInAnimation()
val dismissState = rememberDismissState(
confirmStateChange = {
if (it == DismissValue.DismissedToEnd || it == DismissValue.DismissedToStart) {
showPopup = true
}
false
}
)

SwipeToDismiss(
state = dismissState,
directions = setOf(DismissDirection.StartToEnd, DismissDirection.EndToStart),
dismissThresholds = { FractionalThreshold(0.5f) },
background = {
val direction = dismissState.dismissDirection ?: return@SwipeToDismiss
val color by animateColorAsState(
when (dismissState.targetValue) {
DismissValue.Default -> Color.Transparent
DismissValue.DismissedToEnd -> Color.Red
DismissValue.DismissedToStart -> Color.Red
}
)
val alignment = when (direction) {
DismissDirection.StartToEnd -> Alignment.CenterStart
DismissDirection.EndToStart -> Alignment.CenterEnd
}
val icon = when (direction) {
DismissDirection.StartToEnd -> Icons.Default.Delete
DismissDirection.EndToStart -> Icons.Default.Delete
}
val scale by animateFloatAsState(if (dismissState.targetValue == DismissValue.Default) 0.75f else 1f)

Box(
Modifier
.fillMaxSize()
.background(color)
.padding(horizontal = 20.dp),
contentAlignment = alignment
) {
Icon(
icon,
contentDescription = null,
modifier = Modifier.scale(scale)
)
}
}
) {

Column {
Card(
onClick = {
genericInfo.toSource(item.source)?.getSourceByUrl(item.url)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribeBy { navController.navigate(NotificationFragmentDirections.actionNotificationFragmentToDetailsFragment(it)) }
?.addTo(disposable)
},
elevation = 5.dp,
indication = rememberRipple(),
onClickLabel = item.notiTitle,
modifier = Modifier
.padding(5.dp)
.fadeInAnimation()
) {

Column {

Row {
GlideImage(
imageModel = item.imageUrl.orEmpty(),
contentDescription = "",
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asDrawable()
.override(360, 480)
.thumbnail(0.5f)
.transform(GranularRoundedCorners(0f, 15f, 15f, 0f)),
modifier = Modifier
.align(Alignment.CenterVertically)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT),
failure = {
Image(
painter = rememberDrawablePainter(AppCompatResources.getDrawable(LocalContext.current, logo.logoId)),
contentDescription = item.notiTitle,
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(5.dp)
.size(ComposableUtils.IMAGE_WIDTH, ComposableUtils.IMAGE_HEIGHT)
)
}
)

Column(modifier = Modifier.padding(start = 5.dp)) {
Text(item.notiTitle, style = MaterialTheme.typography.h6)
Divider()
Text(item.source, style = MaterialTheme.typography.subtitle2)
Divider()
Text(item.summaryText, style = MaterialTheme.typography.body2)
}

}

/*Button(
onClick = { showPopup = true },
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(0.dp, 0.dp, 4.dp, 4.dp)
) { Text(stringResource(R.string.remove), style = MaterialTheme.typography.button) }*/

}

//TODO: Below is for a LazyStaggeredVerticalGrid when its finally officially supported
/*Column {
Text(item.notiTitle, style = MaterialTheme.typography.h6, modifier = Modifier.padding(top = 5.dp, start = 5.dp, end = 5.dp))
Text(item.source, style = MaterialTheme.typography.subtitle2, modifier = Modifier.padding(horizontal = 5.dp))
Expand Down Expand Up @@ -261,6 +358,8 @@ class NotificationFragment : BaseBottomSheetDialogFragment() {
shape = RoundedCornerShape(0.dp, 0.dp, 4.dp, 4.dp)
) { Text(stringResource(R.string.remove), style = MaterialTheme.typography.button) }
}*/

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,23 @@ class SettingsFragment : PreferenceFragmentCompat() {

findPreference<Preference>("delete_notifications")?.let { p ->
p.setOnPreferenceClickListener {
itemDao
.deleteAllNotifications()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map { getString(R.string.deleted_notifications, it) }
.subscribeBy {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
requireContext().notificationManager.cancel(42)
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.are_you_sure_delete_notifications)
.setPositiveButton(R.string.yes) { d, _ ->
itemDao
.deleteAllNotifications()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map { getString(R.string.deleted_notifications, it) }
.subscribeBy {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
requireContext().notificationManager.cancel(42)
}
.addTo(disposable)
d.dismiss()
}
.addTo(disposable)
.setNegativeButton(R.string.no) { d, _ -> d.dismiss() }
.show()
true
}
}
Expand Down
21 changes: 17 additions & 4 deletions UIViews/src/main/java/com/programmersbox/uiviews/UpdateChecker.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.programmersbox.uiviews

import android.app.Notification
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import androidx.navigation.NavDeepLinkBuilder
import androidx.work.RxWorker
import androidx.work.WorkerParameters
import com.programmersbox.favoritesdatabase.*
import com.programmersbox.helpfulutils.GroupBehavior
import com.programmersbox.helpfulutils.NotificationDslBuilder
import com.programmersbox.helpfulutils.intersect
import com.programmersbox.helpfulutils.notificationManager
import com.programmersbox.helpfulutils.*
import com.programmersbox.loggingutils.Loged
import com.programmersbox.loggingutils.fd
import com.programmersbox.models.InfoModel
Expand Down Expand Up @@ -225,6 +224,18 @@ class UpdateNotification(private val context: Context) : KoinComponent {
}
showWhen = true
groupId = "otakuGroup"
+actionAction {
actionTitle = "Mark Read"
actionIcon = icon.notificationId
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) semanticAction = SemanticActions.MARK_AS_READ
pendingActionIntent {
val intent = Intent(context, DeleteNotificationReceiver::class.java)
intent.action = "NOTIFICATION_DELETED_ACTION"
intent.putExtra("url", pair.second.url)
intent.putExtra("id", pair.second.hashCode())
PendingIntent.getBroadcast(context, pair.second.hashCode(), intent, PendingIntent.FLAG_IMMUTABLE)
}
}
/*deleteIntent { context ->
val intent = Intent(context, DeleteNotificationReceiver::class.java)
intent.action = "NOTIFICATION_DELETED_ACTION"
Expand Down Expand Up @@ -310,11 +321,13 @@ class DeleteNotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val dao by lazy { context?.let { ItemDatabase.getInstance(it).itemDao() } }
val url = intent?.getStringExtra("url")
val id = intent?.getIntExtra("id", -1)
println(url)
GlobalScope.launch {
url?.let { dao?.getNotificationItem(it) }
.also { println(it) }
?.let { dao?.deleteNotification(it)?.subscribe() }
id?.let { if (it != -1) context?.notificationManager?.cancel(it) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fun CoverCard(imageUrl: String, name: String, placeHolder: Int, error: Int = pla
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
//.override(360, 480)
.placeholder(placeHolder)
.error(error)
Expand Down
1 change: 1 addition & 0 deletions UIViews/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@
<string name="global_search">Global Search</string>
<string name="search">Search</string>
<string name="global_search_by_name">Global Search by Name</string>
<string name="are_you_sure_delete_notifications">Are you sure you want to delete all notifications?</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ViewVideosFragment : BaseBottomSheetDialogFragment() {
contentDescription = "",
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
.override(360, 270)
.thumbnail(0.5f)
.transform(GranularRoundedCorners(0f, 15f, 15f, 0f)),
Expand Down Expand Up @@ -427,7 +427,7 @@ class ViewVideosFragment : BaseBottomSheetDialogFragment() {
contentDescription = "",
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
.override(360, 270)
.thumbnail(0.5f)
.transform(GranularRoundedCorners(0f, 15f, 15f, 0f)),
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ buildscript {
ext.composeRuntimeLivedata = "androidx.compose.runtime:runtime-livedata:$jetpack"
ext.composeRuntimeRxjava2 = "androidx.compose.runtime:runtime-rxjava2:$jetpack"
ext.composeMaterialThemeAdapter = "com.google.android.material:compose-theme-adapter:1.0.1"
ext.landscapistGlide = "com.github.skydoves:landscapist-glide:1.3.3"
ext.landscapistGlide = "com.github.skydoves:landscapist-glide:1.3.5"
ext.composeConstraintLayout = "androidx.constraintlayout:constraintlayout-compose:1.0.0-beta02"
ext.composeAnimation = "androidx.compose.animation:animation:$jetpack"
ext.materialPlaceholder = "com.google.accompanist:accompanist-placeholder-material:$accompanist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fun DetailsHeader(
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
.placeholder(logoId)
.error(logoId)
.fallback(logoId),
Expand Down Expand Up @@ -324,7 +324,7 @@ fun DetailsHeader(
contentDescription = null,
contentScale = ContentScale.Crop,
requestBuilder = Glide.with(LocalView.current)
.asBitmap()
.asDrawable()
//.override(360, 480)
.placeholder(logoId)
.error(logoId)
Expand Down
Loading

0 comments on commit bd35c1d

Please sign in to comment.