Archived
Project cleanup; removed unused resources and test classes. Fixed memory leak bug in DataFetcher.kt
This commit is contained in:
@@ -13,14 +13,14 @@ import com.google.android.material.card.MaterialCardView
|
||||
|
||||
internal class ColourAdapter(private var mColours: List<Colour>, onClickListener: OnClickListener) : RecyclerView.Adapter<ColourAdapter.ColourViewHolder>() {
|
||||
|
||||
val mOnClickListener = onClickListener
|
||||
private val mOnClickListener = onClickListener
|
||||
|
||||
class ColourViewHolder(view: View, clickListener: OnClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
|
||||
val title: TextView = view.findViewById(R.id.item_text)
|
||||
var image: ImageView = view.findViewById(R.id.item_image)
|
||||
val titleNoLang: TextView = view.findViewById(R.id.item_text_no_lang)
|
||||
val cardView: MaterialCardView = view.findViewById(R.id.cardView)
|
||||
val mClickListener = clickListener
|
||||
private val mClickListener = clickListener
|
||||
init { view.setOnClickListener(this) }
|
||||
|
||||
override fun onClick(v: View?) { mClickListener.onClick(adapterPosition, title.text.toString(), titleNoLang.text.toString()) }
|
||||
@@ -59,12 +59,7 @@ internal class ColourAdapter(private var mColours: List<Colour>, onClickListener
|
||||
|
||||
override fun getItemCount(): Int = mColours.size
|
||||
|
||||
fun setColours(colours: List<Colour>) {
|
||||
mColours = colours
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
public interface OnClickListener {
|
||||
internal interface OnClickListener {
|
||||
fun onClick(position: Int, title: String, titleNoLang: String)
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,6 @@ internal class FoodAdapter(food: ArrayList<Food>) : RecyclerView.Adapter<FoodAda
|
||||
return CardViewHolder(v)
|
||||
}
|
||||
|
||||
fun getFoodAt(i: Int): Food {
|
||||
return mFood!![i]
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
|
||||
val currentItem = mFood!![position]
|
||||
|
||||
|
||||
@@ -45,12 +45,7 @@ internal class RingtoneAdapter(private var _ringtones: List<Ringtone>, onClickLi
|
||||
|
||||
override fun getItemCount(): Int = _ringtones.size
|
||||
|
||||
fun setRingtones(ringtones: List<Ringtone>) {
|
||||
_ringtones = ringtones
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
public interface OnClickListener {
|
||||
internal interface OnClickListener {
|
||||
fun onRingtoneClick(position: Int, name: String, uri: String)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.models.Subst
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.jsoup.Jsoup
|
||||
import java.lang.ref.WeakReference
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
/**
|
||||
@@ -40,13 +41,13 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
private var menu = isMenu
|
||||
private var forceRefresh = forced
|
||||
|
||||
private var mContext = context
|
||||
private var mContext = WeakReference(context)
|
||||
private var mApplication = application
|
||||
private var mView = parentView
|
||||
private var mView = WeakReference(parentView)
|
||||
private var priority = 200
|
||||
private var notifText = ""
|
||||
private var notificationText = ""
|
||||
private var informational = ""
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext)
|
||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext.get())
|
||||
private val edit = prefs.edit()
|
||||
private var currentTime = ""
|
||||
private var currentFoodTime = ""
|
||||
@@ -72,21 +73,21 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
|
||||
if (plan || menu) {
|
||||
mView?.let { v: View ->
|
||||
var snackText = "${mContext.getText(R.string.lastUpdated)} ${when {
|
||||
mView.get()?.let { v: View ->
|
||||
var snackText = "${mContext.get()?.getText(R.string.lastUpdated)} ${when {
|
||||
plan -> currentTime
|
||||
menu -> currentFoodTime
|
||||
else -> "---"
|
||||
}}"
|
||||
snackText = if (forceRefresh) mContext.getString(R.string.forcedRefresh) else snackText
|
||||
snackText = if (forceRefresh) mContext.get()?.getString(R.string.forcedRefresh) ?: "" else snackText
|
||||
val snackBarView = v.findViewById<View>(R.id.coordination)
|
||||
Snackbar.make(snackBarView, snackText, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
mView?.let { v: View ->
|
||||
mView.get()?.let { v: View ->
|
||||
val snackBarView = v.findViewById<View>(R.id.coordination)
|
||||
Snackbar.make(snackBarView, mContext.getString(R.string.noInternet), Snackbar.LENGTH_LONG).setBackgroundTint(ContextCompat.getColor(mContext,
|
||||
Snackbar.make(snackBarView, mContext.get()?.getString(R.string.noInternet) ?: "", Snackbar.LENGTH_LONG).setBackgroundTint(ContextCompat.getColor(mContext.get()!!,
|
||||
R.color.colorError
|
||||
)).show()
|
||||
}
|
||||
@@ -95,11 +96,13 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Void?) {
|
||||
mView?.let {
|
||||
mView.get()?.let {
|
||||
try {
|
||||
it.findViewById<SwipeRefreshLayout>(R.id.pullToRefresh).isRefreshing = false
|
||||
} catch (ignored: Exception) {}
|
||||
}
|
||||
mView.clear()
|
||||
mContext.clear()
|
||||
}
|
||||
|
||||
private fun requestFoodMenuData() {
|
||||
@@ -184,11 +187,11 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
false
|
||||
)
|
||||
}.forEach { substItem ->
|
||||
notifText += "${if (notifText.isNotEmpty()) ",\n" else ""}${substItem.course}: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}"
|
||||
notificationText += "${if (notificationText.isNotEmpty()) ",\n" else ""}${substItem.course}: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}"
|
||||
}
|
||||
}
|
||||
|
||||
if (notifText.isNotEmpty()) {
|
||||
if (notificationText.isNotEmpty()) {
|
||||
sendNotification()
|
||||
}
|
||||
|
||||
@@ -197,40 +200,42 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
|
||||
private fun sendNotification() {
|
||||
val openApp = Intent(mContext, Main::class.java)
|
||||
openApp.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
val openAppPending = PendingIntent.getActivity(mContext, 0, openApp, 0)
|
||||
mContext.get()?.let { c ->
|
||||
val openApp = Intent(c, Main::class.java)
|
||||
openApp.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
val openAppPending = PendingIntent.getActivity(c, 0, openApp, 0)
|
||||
|
||||
val notificationLayout = RemoteViews(mContext.packageName, R.layout.notification)
|
||||
notificationLayout.setTextViewText(R.id.notification_title, mContext.getString(
|
||||
val notificationLayout = RemoteViews(c.packageName, R.layout.notification)
|
||||
notificationLayout.setTextViewText(R.id.notification_title, c.getString(
|
||||
R.string.substitutionPlan
|
||||
))
|
||||
notificationLayout.setTextViewText(R.id.notification_textview, notifText)
|
||||
notificationLayout.setTextViewText(R.id.notification_textview, notificationText)
|
||||
|
||||
val manager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val manager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
HelperFunctions.getNotificationChannel(mContext, prefs)
|
||||
}
|
||||
|
||||
val notification = NotificationCompat.Builder(mContext, HelperFunctions.notificationChannelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.setColor(ContextCompat.getColor(mContext, R.color.colorAccent))
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
val sound = if ((prefs.getString("ringtoneUri", "") ?: "").isNotEmpty()) {
|
||||
Uri.parse(prefs.getString("ringtoneUri", "") ?: "")
|
||||
} else {
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
HelperFunctions.getNotificationChannel(c, prefs)
|
||||
}
|
||||
notification.setSound(sound)
|
||||
}
|
||||
|
||||
manager.notify(1, notification.build())
|
||||
val notification = NotificationCompat.Builder(c, HelperFunctions.notificationChannelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.setColor(ContextCompat.getColor(c, R.color.colorAccent))
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
val sound = if ((prefs.getString("ringtoneUri", "") ?: "").isNotEmpty()) {
|
||||
Uri.parse(prefs.getString("ringtoneUri", "") ?: "")
|
||||
} else {
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
}
|
||||
notification.setSound(sound)
|
||||
}
|
||||
|
||||
manager.notify(1, notification.build())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,4 @@ internal class FoodViewModel(application: Application) : AndroidViewModel(applic
|
||||
init {
|
||||
allFoods = repository.allFoods
|
||||
}
|
||||
|
||||
fun insert(food: Food) {
|
||||
repository.insert(food)
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
repository.deleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,6 @@ internal class SubstRepository(application: Application) {
|
||||
InsertSubstAsync(substDao).execute(subst)
|
||||
}
|
||||
|
||||
fun update(subst: Subst) {
|
||||
UpdateSubstAsync(substDao).execute(subst)
|
||||
}
|
||||
|
||||
fun delete(subst: Subst) {
|
||||
DeleteSubstAsync(substDao).execute(subst)
|
||||
}
|
||||
|
||||
fun deleteAllSubst() {
|
||||
DeleteAllSubstAsync(substDao).execute()
|
||||
}
|
||||
@@ -42,22 +34,6 @@ internal class SubstRepository(application: Application) {
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateSubstAsync(substDao: SubstDao?) : AsyncTask<Subst, Void, Void>() {
|
||||
private val mSubstDao = substDao
|
||||
override fun doInBackground(vararg substs: Subst): Void? {
|
||||
mSubstDao?.updateSubst(substs[0])
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteSubstAsync(substDao: SubstDao?) : AsyncTask<Subst, Void, Void>() {
|
||||
private val mSubstDao = substDao
|
||||
override fun doInBackground(vararg substs: Subst): Void? {
|
||||
mSubstDao?.deleteSubst(substs[0])
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteAllSubstAsync(substDao: SubstDao?) : AsyncTask<Void, Void, Void>() {
|
||||
private val mSubstDao = substDao
|
||||
override fun doInBackground(vararg voids: Void): Void? {
|
||||
|
||||
@@ -14,20 +14,4 @@ internal class SubstViewModel(application: Application) : AndroidViewModel(appli
|
||||
init {
|
||||
allSubst = repository.allSubst
|
||||
}
|
||||
|
||||
fun insertSubst(subst: Subst) {
|
||||
repository.insert(subst)
|
||||
}
|
||||
|
||||
fun updateSubst(subst: Subst) {
|
||||
repository.update(subst)
|
||||
}
|
||||
|
||||
fun deleteSubst(subst: Subst) {
|
||||
repository.delete(subst)
|
||||
}
|
||||
|
||||
fun deleteAllSubst() {
|
||||
repository.deleteAllSubst()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user