mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-14 02:01:56 +00:00
Clean up code
This commit is contained in:
parent
42b3797ebb
commit
6640e570b5
6 changed files with 4 additions and 264 deletions
|
|
@ -35,7 +35,7 @@ open class Task : RealmObject, Parcelable {
|
|||
var value: Double = 0.0
|
||||
var tags: RealmList<Tag>? = RealmList()
|
||||
var dateCreated: Date? = null
|
||||
var position: Int? = 0
|
||||
var position: Int = 0
|
||||
var group: TaskGroupPlan? = null
|
||||
//Habits
|
||||
var up: Boolean? = false
|
||||
|
|
|
|||
|
|
@ -1,114 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.tasks
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.models.tasks.ChecklistItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperAdapter
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperViewHolder
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaAutocompleteTextView
|
||||
import net.pherth.android.emoji_library.EmojiEditText
|
||||
import java.util.*
|
||||
|
||||
class CheckListAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<CheckListAdapter.ItemViewHolder>(), ItemTouchHelperAdapter {
|
||||
|
||||
private val items = ArrayList<ChecklistItem>()
|
||||
|
||||
val checkListItems: List<ChecklistItem>
|
||||
get() = items
|
||||
|
||||
fun setItems(items: List<ChecklistItem>) {
|
||||
this.items.addAll(items)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.checklist_item, parent, false)
|
||||
return ItemViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
|
||||
holder.textWatcher.id = null
|
||||
holder.checkListTextView.setText(items[position].text)
|
||||
holder.textWatcher.id = items[position].id
|
||||
}
|
||||
|
||||
fun addItem(item: ChecklistItem) {
|
||||
items.add(item)
|
||||
notifyItemInserted(items.size - 1)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return items.size
|
||||
}
|
||||
|
||||
override fun onItemDismiss(position: Int) {
|
||||
if (position >= 0 && position < items.size) {
|
||||
items.removeAt(position)
|
||||
notifyItemRemoved(position)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onItemMove(fromPosition: Int, toPosition: Int) {
|
||||
val item = items[fromPosition]
|
||||
items.removeAt(fromPosition)
|
||||
items.add(toPosition, item)
|
||||
notifyItemMoved(fromPosition, toPosition)
|
||||
}
|
||||
|
||||
inner class ItemViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView), ItemTouchHelperViewHolder, View.OnClickListener {
|
||||
|
||||
internal val textWatcher: ChecklistTextWatcher = ChecklistTextWatcher()
|
||||
internal val checkListTextView: HabiticaAutocompleteTextView by bindView(itemView, R.id.item_edittext)
|
||||
private val deleteButton: Button by bindView(itemView, R.id.delete_item_button)
|
||||
|
||||
init {
|
||||
deleteButton.setOnClickListener(this)
|
||||
checkListTextView.addTextChangedListener(textWatcher)
|
||||
}
|
||||
|
||||
override fun onItemSelected() {
|
||||
itemView.setBackgroundColor(Color.LTGRAY)
|
||||
}
|
||||
|
||||
override fun onItemClear() {
|
||||
itemView.setBackgroundColor(0)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v === deleteButton) {
|
||||
this@CheckListAdapter.onItemDismiss(adapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
internal inner class ChecklistTextWatcher : TextWatcher {
|
||||
|
||||
var id: String? = null
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
if (id == null) {
|
||||
return
|
||||
}
|
||||
for (item in items) {
|
||||
if (id == item.id) {
|
||||
item.text = checkListTextView.text.toString()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.tasks
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -9,7 +8,6 @@ import com.habitrpg.android.habitica.models.tasks.Task
|
|||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder
|
||||
import io.reactivex.BackpressureStrategy
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.functions.Action
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.realm.OrderedRealmCollection
|
||||
|
|
|
|||
|
|
@ -1,114 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.tasks
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.helpers.RemindersManager
|
||||
import com.habitrpg.android.habitica.models.tasks.RemindersItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperAdapter
|
||||
import com.habitrpg.android.habitica.ui.helpers.ItemTouchHelperViewHolder
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 5/31/16.
|
||||
*/
|
||||
class RemindersAdapter(private val taskType: String) : androidx.recyclerview.widget.RecyclerView.Adapter<RemindersAdapter.ItemViewHolder>(), ItemTouchHelperAdapter, RemindersManager.ReminderTimeSelectedCallback {
|
||||
|
||||
private val reminders = ArrayList<RemindersItem>()
|
||||
private val remindersManager: RemindersManager = RemindersManager(taskType)
|
||||
|
||||
val remindersItems: List<RemindersItem>
|
||||
get() = reminders
|
||||
|
||||
fun setReminders(reminders: List<RemindersItem>) {
|
||||
this.reminders.addAll(reminders)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.reminder_item, parent, false)
|
||||
return ItemViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
|
||||
val time = reminders[position].time
|
||||
holder.reminderItemTextView.setText(remindersManager.reminderTimeToString(time))
|
||||
@Suppress("DEPRECATION")
|
||||
holder.hour = time?.hours ?: 0
|
||||
@Suppress("DEPRECATION")
|
||||
holder.minute = time?.minutes ?: 0
|
||||
}
|
||||
|
||||
fun addItem(item: RemindersItem) {
|
||||
reminders.add(item)
|
||||
notifyItemInserted(reminders.size - 1)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return reminders.size
|
||||
}
|
||||
|
||||
|
||||
override fun onItemDismiss(position: Int) {
|
||||
if (position >= 0 && position < reminders.size) {
|
||||
reminders.removeAt(position)
|
||||
notifyItemRemoved(position)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemMove(fromPosition: Int, toPosition: Int) {
|
||||
Collections.swap(reminders, fromPosition, toPosition)
|
||||
notifyItemMoved(fromPosition, toPosition)
|
||||
}
|
||||
|
||||
override fun onReminderTimeSelected(remindersItem: RemindersItem?) {
|
||||
if (remindersItem == null) {
|
||||
return
|
||||
}
|
||||
for (pos in reminders.indices) {
|
||||
if (remindersItem.id == reminders[pos].id) {
|
||||
reminders[pos] = remindersItem
|
||||
notifyItemChanged(pos)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class ItemViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView), ItemTouchHelperViewHolder, View.OnClickListener {
|
||||
|
||||
internal val reminderItemTextView: EditText by bindView(itemView, R.id.item_edittext)
|
||||
private val deleteButton: Button by bindView(itemView, R.id.delete_item_button)
|
||||
|
||||
var hour: Int = 0
|
||||
var minute: Int = 0
|
||||
|
||||
init {
|
||||
deleteButton.setOnClickListener(this)
|
||||
|
||||
reminderItemTextView.setOnClickListener { v ->
|
||||
val reminder = reminders[adapterPosition]
|
||||
|
||||
remindersManager.createReminderTimeDialog(this@RemindersAdapter, taskType, v.context, reminder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemSelected() {
|
||||
itemView.setBackgroundColor(Color.LTGRAY)
|
||||
}
|
||||
|
||||
override fun onItemClear() {
|
||||
itemView.setBackgroundColor(0)
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v === deleteButton) {
|
||||
this@RemindersAdapter.onItemDismiss(adapterPosition)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class BottomNavigationBehavior<V extends View> extends VerticalScrollingBehavior
|
|||
private ViewPropertyAnimatorCompat mTranslationAnimator;
|
||||
private boolean hidden = false;
|
||||
private int mSnackbarHeight = -1;
|
||||
private final BottomNavigationWithSnackbar mWithSnackBarImpl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? new LollipopBottomNavWithSnackBarImpl() : new PreLollipopBottomNavWithSnackBarImpl();
|
||||
private final BottomNavigationWithSnackbar mWithSnackBarImpl = new LollipopBottomNavWithSnackBarImpl();
|
||||
private boolean mScrollingEnabled = true;
|
||||
|
||||
BottomNavigationBehavior(int bottomNavHeight, int defaultOffset, boolean tablet) {
|
||||
|
|
@ -135,30 +135,6 @@ class BottomNavigationBehavior<V extends View> extends VerticalScrollingBehavior
|
|||
void updateSnackbar(CoordinatorLayout parent, View dependency, View child);
|
||||
}
|
||||
|
||||
|
||||
private class PreLollipopBottomNavWithSnackBarImpl implements BottomNavigationWithSnackbar {
|
||||
|
||||
@Override
|
||||
public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) {
|
||||
if (!isTablet && dependency instanceof Snackbar.SnackbarLayout) {
|
||||
if (mSnackbarHeight == -1) {
|
||||
mSnackbarHeight = dependency.getHeight();
|
||||
}
|
||||
if (ViewCompat.getTranslationY(child) != 0) return;
|
||||
int targetPadding = bottomNavHeight + mSnackbarHeight - defaultOffset;
|
||||
|
||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dependency.getLayoutParams();
|
||||
layoutParams.bottomMargin = targetPadding;
|
||||
child.bringToFront();
|
||||
child.getParent().requestLayout();
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
((View) child.getParent()).invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LollipopBottomNavWithSnackBarImpl implements BottomNavigationWithSnackbar {
|
||||
@Override
|
||||
public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) {
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ public class BitmapUtils {
|
|||
public static void saveToFile(String filename, Bitmap bmp) {
|
||||
try {
|
||||
createNomedia();
|
||||
File myDir = new File(getSavePath());
|
||||
boolean res = myDir.mkdirs();
|
||||
|
||||
filename = getSavePath() + "/" + filename;
|
||||
|
||||
FileOutputStream out = new FileOutputStream(filename);
|
||||
|
|
@ -51,9 +48,6 @@ public class BitmapUtils {
|
|||
|
||||
public static File saveToShareableFile(String directory, String filename, Bitmap bmp) {
|
||||
try {
|
||||
File myDir = new File(directory);
|
||||
boolean res = myDir.mkdirs();
|
||||
|
||||
filename = directory + "/" + filename;
|
||||
|
||||
FileOutputStream out = new FileOutputStream(filename);
|
||||
|
|
@ -61,7 +55,7 @@ public class BitmapUtils {
|
|||
out.flush();
|
||||
out.close();
|
||||
return new File(filename);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -78,7 +72,7 @@ public class BitmapUtils {
|
|||
cacheDir.mkdirs();
|
||||
File nomediaFile = new File(getSavePath() + "/.nomedia");
|
||||
if (!nomediaFile.isFile()) return nomediaFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue