[Dialog/BellSync] Add showing info when there are no lessons.

This commit is contained in:
Kacper Ziubryniewicz 2019-12-21 20:46:26 +01:00
parent b399a3f5ad
commit b66bd6fec9
14 changed files with 196 additions and 347 deletions

View File

@ -59,6 +59,10 @@ class BellSyncDialog(
.setTitle(R.string.bell_sync_title)
.setView(b.root)
.setNeutralButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
.setOnDismissListener {
counterJob?.cancel()
onDismissListener?.invoke(TAG)
}
.show()
initView()
}}

View File

@ -12,7 +12,6 @@ import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.MainActivity
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.DialogBellSyncTimeChooseBinding
import pl.szczodrzynski.edziennik.onClick
import pl.szczodrzynski.edziennik.utils.TextInputDropDown
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Time
@ -26,6 +25,8 @@ class BellSyncTimeChooseDialog(
companion object {
const val TAG = "BellSyncTimeChooseDialog"
private const val MAX_DIFF_MINUTES = 10
}
private lateinit var job: Job
@ -39,7 +40,7 @@ class BellSyncTimeChooseDialog(
private val today = Date.getToday()
private val selectedTime: Time?
get() = b.timeDropdown.selected?.id?.let { Time.fromValue(it.toInt()) }
get() = b.timeDropdown.selected?.tag as Time?
init { apply {
if (activity.isFinishing)
@ -57,15 +58,15 @@ class BellSyncTimeChooseDialog(
}
}
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
.setNeutralButton(R.string.reset, null)
.setOnDismissListener {
onDismissListener?.invoke(TAG)
}
.show()
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).onClick {
.create()
.apply {
setButton(AlertDialog.BUTTON_NEUTRAL, app.getString(R.string.reset)) { _, _ ->
showResetDialog()
}
}
initView()
}}
@ -85,6 +86,17 @@ class BellSyncTimeChooseDialog(
loadTimeList()
}
private fun checkForLessons(timeList: List<Time>): Boolean {
return if (timeList.isNotEmpty()) {
val now = Time.getNow()
val first = timeList.first()
val last = timeList.last()
now.stepForward(0, MAX_DIFF_MINUTES, 0) >= first &&
now.stepForward(0, -1 * MAX_DIFF_MINUTES, 0) <= last
} else false
}
private fun loadTimeList() { launch {
val timeItems = withContext(Dispatchers.Default) {
val lessons = app.db.timetableDao().getForDateNow(App.profileId, today)
@ -94,23 +106,31 @@ class BellSyncTimeChooseDialog(
items += TextInputDropDown.Item(
it.startTime?.value?.toLong() ?: return@forEach,
app.getString(R.string.bell_sync_lesson_item, it.displaySubjectName, it.startTime?.stringHM),
tag = it
tag = it.startTime
)
items += TextInputDropDown.Item(
it.endTime?.value?.toLong() ?: return@forEach,
app.getString(R.string.bell_sync_break_item, it.endTime?.stringHM),
tag = it
tag = it.endTime
)
}
items
}
if (!checkForLessons(timeItems.map { it.tag as Time })) {
/* Synchronization not possible */
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.bell_sync_title)
.setMessage(R.string.bell_sync_cannot_now)
.setPositiveButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
.show()
} else {
b.timeDropdown.clear()
b.timeDropdown.append(timeItems)
timeItems.forEachIndexed { index, item ->
val time = Time.fromValue(item.id.toInt())
val time = item.tag as Time
if (time < Time.getNow()) {
b.timeDropdown.select(if (timeItems.size > index + 1) timeItems[index + 1] else item)
}
@ -118,6 +138,9 @@ class BellSyncTimeChooseDialog(
b.timeDropdown.isEnabled = true
// TODO Fix popup cutting off
dialog.show()
}
}}
private fun showResetDialog() {

View File

@ -20,7 +20,7 @@ import pl.szczodrzynski.edziennik.databinding.ActivityCounterBinding;
import pl.szczodrzynski.edziennik.utils.models.Date;
import pl.szczodrzynski.edziennik.utils.models.Time;
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.updateInterval;
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld.updateInterval;
public class CounterActivity extends AppCompatActivity {
@ -153,7 +153,7 @@ public class CounterActivity extends AppCompatActivity {
private short counterType = TIME_LEFT;
private long updateCounter(Time syncedNow) {
Time diff = Time.diff(counterTarget, syncedNow);
b.timeLeft.setText(counterType == TIME_TILL ? HomeFragment.timeTill(app, diff, app.config.getTimetable().getCountInSeconds(), "\n") : HomeFragment.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds(), "\n"));
b.timeLeft.setText(counterType == TIME_TILL ? HomeFragmentOld.timeTill(app, diff, app.config.getTimetable().getCountInSeconds(), "\n") : HomeFragmentOld.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds(), "\n"));
return updateInterval(app, diff);
}

View File

@ -26,7 +26,7 @@ import kotlinx.coroutines.Job
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.MainActivity
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.databinding.FragmentHomeV2Binding
import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding
import pl.szczodrzynski.edziennik.ui.dialogs.home.StudentNumberDialog
import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeGradesCard
import pl.szczodrzynski.edziennik.ui.modules.home.cards.HomeLuckyNumberCard
@ -38,7 +38,7 @@ import kotlin.coroutines.CoroutineContext
class HomeFragmentV2 : Fragment(), CoroutineScope {
companion object {
private const val TAG = "HomeFragment"
private const val TAG = "HomeFragmentOld"
fun swapCards(fromPosition: Int, toPosition: Int, cardAdapter: HomeCardAdapter) {
val homeCards = App.getConfig().ui.homeCards.toMutableList()
@ -56,7 +56,7 @@ class HomeFragmentV2 : Fragment(), CoroutineScope {
private lateinit var app: App
private lateinit var activity: MainActivity
private lateinit var b: FragmentHomeV2Binding
private lateinit var b: FragmentHomeBinding
private lateinit var job: Job
override val coroutineContext: CoroutineContext
@ -67,7 +67,7 @@ class HomeFragmentV2 : Fragment(), CoroutineScope {
context ?: return null
app = activity.application as App
context!!.theme.applyStyle(Themes.appTheme, true)
b = FragmentHomeV2Binding.inflate(inflater)
b = FragmentHomeBinding.inflate(inflater)
b.refreshLayout.setParent(activity.swipeRefreshLayout)
job = Job()
return b.root

View File

@ -53,7 +53,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject;
import pl.szczodrzynski.edziennik.databinding.CardLuckyNumberBinding;
import pl.szczodrzynski.edziennik.databinding.CardUpdateBinding;
import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding;
import pl.szczodrzynski.edziennik.databinding.FragmentHomeOldBinding;
import pl.szczodrzynski.edziennik.receivers.BootReceiver;
import pl.szczodrzynski.edziennik.ui.modules.login.LoginLibrusCaptchaActivity;
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeActivity;
@ -67,7 +67,6 @@ import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem;
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem;
import static pl.szczodrzynski.edziennik.App.UPDATES_ON_PLAY_STORE;
import static pl.szczodrzynski.edziennik.MainActivity.DRAWER_ITEM_GRADES;
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER1_FINAL;
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER1_PROPOSED;
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER2_FINAL;
@ -76,11 +75,11 @@ import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_YEAR_
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_YEAR_PROPOSED;
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_MOBIDZIENNIK;
public class HomeFragment extends Fragment {
private static final String TAG = "HomeFragment";
public class HomeFragmentOld extends Fragment {
private static final String TAG = "HomeFragmentOld";
private App app = null;
private MainActivity activity = null;
private FragmentHomeBinding b = null;
private FragmentHomeOldBinding b = null;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -92,7 +91,7 @@ public class HomeFragment extends Fragment {
if (app.profile == null)
return inflater.inflate(R.layout.fragment_loading, container, false);
// activity, context and profile is valid
b = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
b = DataBindingUtil.inflate(inflater, R.layout.fragment_home_old, container, false);
b.refreshLayout.setParent(activity.getSwipeRefreshLayout());
return b.getRoot();
}
@ -261,7 +260,7 @@ public class HomeFragment extends Fragment {
b.cardLuckyNumber.setOnClickListener(v1 -> setNumberDialog());
}
timetableCard = new HomeTimetableCard(app, activity, this, layoutInflater, insertPoint);
timetableCard = new HomeTimetableCardOld(app, activity, this, layoutInflater, insertPoint);
timetableCard.run();
configCardGrades(activity, layoutInflater, activity, insertPoint);
@ -571,7 +570,7 @@ public class HomeFragment extends Fragment {
Button cardGradesButton = root.findViewById(R.id.cardGradesButton);
buttonAddDrawable(c, cardGradesButton, CommunityMaterial.Icon.cmd_arrow_right);
cardGradesButton.setOnClickListener((v1 -> new Handler().postDelayed(() -> a.runOnUiThread(() -> {
activity.loadTarget(DRAWER_ITEM_GRADES, null);
activity.loadTarget(MainActivity.DRAWER_ITEM_GRADES, null);
}), 100)));
//new Handler().postDelayed(() -> a.runOnUiThread(() -> updateCardGrades(c, a, root)), newRefreshInterval);
@ -591,5 +590,5 @@ public class HomeFragment extends Fragment {
insertPoint.addView(root, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
private HomeTimetableCard timetableCard;
private HomeTimetableCardOld timetableCard;
}

View File

@ -1,177 +0,0 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-11-22
*/
package pl.szczodrzynski.edziennik.ui.modules.home
import android.content.Intent
import android.os.AsyncTask
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.databinding.DataBindingUtil
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.MainActivity
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.databinding.CardTimetableBinding
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.updateInterval
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Time
import java.util.*
class HomeTimetableCard(
private val app: App,
private val activity: MainActivity,
private val homeFragment: HomeFragment,
private val layoutInflater: LayoutInflater,
private val insertPoint: ViewGroup
) {
companion object {
private const val TAG = "HomeTimetableCard"
const val TIME_TILL = 0
const val TIME_LEFT = 1
}
private lateinit var timetableTimer: Timer
private lateinit var b: CardTimetableBinding
private var bellSyncTime: Time? = null
private var counterType = TIME_TILL
private val counterTarget = Time(0, 0, 0)
private val lessons = mutableListOf<Lesson>()
private val events = mutableListOf<Event>()
fun run() {
timetableTimer = Timer()
b = DataBindingUtil.inflate(layoutInflater, R.layout.card_timetable, null, false)
update()
insertPoint.addView(b.root, ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT))
b.cardTimetableFullscreenCounter.setOnClickListener {
activity.startActivity(Intent(activity, CounterActivity::class.java))
}
b.cardTimetableBellSync.setOnClickListener {
if (bellSyncTime == null) {
MaterialDialog.Builder(activity)
.title(R.string.bell_sync_title)
.content(R.string.bell_sync_cannot_now)
.positiveText(R.string.ok)
.show()
} else {
MaterialDialog.Builder(activity)
.title(R.string.bell_sync_title)
.content(app.getString(R.string.bell_sync_howto, bellSyncTime!!.stringHM).toString() +
when {
app.config.timetable.bellSyncDiff != null -> app.getString(R.string.bell_sync_current_dialog,
(if (app.config.timetable.bellSyncMultiplier == -1) "-" else "+") + app.config.timetable.bellSyncDiff?.stringHMS)
else -> ""
})
.positiveText(R.string.ok)
.negativeText(R.string.cancel)
.neutralText(R.string.reset)
.onPositive { _, _: DialogAction? ->
val bellDiff = Time.diff(Time.getNow(), bellSyncTime)
app.config.timetable.bellSyncDiff = bellDiff
app.config.timetable.bellSyncMultiplier = if (bellSyncTime!!.value > Time.getNow().value) -1 else 1
MaterialDialog.Builder(activity)
.title(R.string.bell_sync_title)
.content(app.getString(R.string.bell_sync_results, if (bellSyncTime!!.value > Time.getNow().value) "-" else "+", bellDiff.stringHMS))
.positiveText(R.string.ok)
.show()
}
.onNeutral { _, _ ->
MaterialDialog.Builder(activity)
.title(R.string.bell_sync_title)
.content(R.string.bell_sync_reset_confirm)
.positiveText(R.string.yes)
.negativeText(R.string.no)
.onPositive { _, _ ->
app.config.timetable.bellSyncDiff = null
app.config.timetable.bellSyncMultiplier = 0
app.saveConfig("bellSyncDiff", "bellSyncMultiplier")
}
.show()
}
.show()
}
}
HomeFragment.buttonAddDrawable(activity, b.cardTimetableButton, CommunityMaterial.Icon.cmd_arrow_right)
}
fun destroy() {
try {
timetableTimer.apply {
cancel()
purge()
}
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun update() {
if (!homeFragment.isAdded) return
val now = Time.getNow()
val syncedNow: Time = when (app.config.timetable.bellSyncDiff != null) {
true -> when {
app.config.timetable.bellSyncMultiplier < 0 -> Time.sum(now, app.config.timetable.bellSyncDiff)
app.config.timetable.bellSyncMultiplier > 0 -> Time.diff(now, app.config.timetable.bellSyncDiff)
else -> now
}
else -> now
}
if (lessons.size == 0 || syncedNow.value > counterTarget.value) {
findLessons(syncedNow)
} else {
scheduleUpdate(updateCounter(syncedNow))
}
}
private fun updateCounter(syncedNow: Time): Long {
val diff = Time.diff(counterTarget, syncedNow)
b.cardTimetableTimeLeft.text = when (counterType) {
TIME_TILL -> HomeFragment.timeTill(app, diff, app.config.timetable.countInSeconds)
else -> HomeFragment.timeLeft(app, diff, app.config.timetable.countInSeconds)
}
bellSyncTime = counterTarget.clone()
b.cardTimetableFullscreenCounter.visibility = View.VISIBLE
return updateInterval(app, diff)
}
private fun scheduleUpdate(newRefreshInterval: Long) {
timetableTimer.schedule(object : TimerTask() {
override fun run() {
activity.runOnUiThread { update() }
}
}, newRefreshInterval)
}
private fun findLessons(syncedNow: Time) {
AsyncTask.execute {
val today = Date.getToday()
val searchEnd = Date.getToday().stepForward(0, 0, -today.weekDay)
lessons.apply {
clear()
addAll(app.db.timetableDao().getBetweenDatesNow(today, searchEnd))
}
}
}
}

View File

@ -32,21 +32,21 @@ import pl.szczodrzynski.edziennik.utils.models.Week;
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CANCELLED;
import static pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange.TYPE_CHANGE;
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.updateInterval;
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld.updateInterval;
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
public class HomeTimetableCardOld {
private static final String TAG = "HomeTimetableCardOld";
private App app;
private MainActivity a;
private HomeFragment f;
private HomeFragmentOld f;
private LayoutInflater layoutInflater;
private ViewGroup insertPoint;
private CardTimetableBinding b;
private Timer timetableTimer;
private Time bellSyncTime = null;
public HomeTimetableCardOld(App app, MainActivity a, HomeFragment f, LayoutInflater layoutInflater, ViewGroup insertPoint) {
public HomeTimetableCardOld(App app, MainActivity a, HomeFragmentOld f, LayoutInflater layoutInflater, ViewGroup insertPoint) {
this.app = app;
this.a = a;
this.f = f;
@ -109,7 +109,7 @@ public class HomeTimetableCardOld {
}
});
HomeFragment.buttonAddDrawable(a, b.cardTimetableButton, CommunityMaterial.Icon.cmd_arrow_right);
HomeFragmentOld.buttonAddDrawable(a, b.cardTimetableButton, CommunityMaterial.Icon.cmd_arrow_right);
}
private List<LessonFull> lessons = new ArrayList<>();
@ -228,7 +228,7 @@ public class HomeTimetableCardOld {
private short counterType = TIME_TILL;
private long updateCounter(Time syncedNow) {
Time diff = Time.diff(counterTarget, syncedNow);
b.cardTimetableTimeLeft.setText(counterType == TIME_TILL ? HomeFragment.timeTill(app, diff, app.config.getTimetable().getCountInSeconds()) : HomeFragment.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds()));
b.cardTimetableTimeLeft.setText(counterType == TIME_TILL ? HomeFragmentOld.timeTill(app, diff, app.config.getTimetable().getCountInSeconds()) : HomeFragmentOld.timeLeft(app, diff, app.config.getTimetable().getCountInSeconds()));
bellSyncTime = counterTarget;
b.cardTimetableFullscreenCounter.setVisibility(View.VISIBLE);
return updateInterval(app, diff);

View File

@ -21,7 +21,7 @@ import pl.szczodrzynski.edziennik.MainActivity;
import pl.szczodrzynski.edziennik.R;
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld;
import pl.szczodrzynski.edziennik.utils.models.Date;
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
@ -53,7 +53,7 @@ public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHo
else if (dayDiff == 2) {
return context.getString(R.string.the_day_after);
}
return HomeFragment.plural(context, R.plurals.time_till_days, Math.abs(dayDiff));
return HomeFragmentOld.plural(context, R.plurals.time_till_days, Math.abs(dayDiff));
}
else if (dayDiff < 0) {
if (dayDiff == -1) {
@ -62,7 +62,7 @@ public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHo
else if (dayDiff == -2) {
return context.getString(R.string.the_day_before);
}
return context.getString(R.string.ago_format, HomeFragment.plural(context, R.plurals.time_till_days, Math.abs(dayDiff)));
return context.getString(R.string.ago_format, HomeFragmentOld.plural(context, R.plurals.time_till_days, Math.abs(dayDiff)));
}
return context.getString(R.string.today);
}

View File

@ -52,7 +52,7 @@ import pl.szczodrzynski.edziennik.receivers.BootReceiver;
import pl.szczodrzynski.edziennik.sync.SyncWorker;
import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog;
import pl.szczodrzynski.edziennik.ui.dialogs.settings.ProfileRemoveDialog;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld;
import pl.szczodrzynski.edziennik.utils.Themes;
import pl.szczodrzynski.edziennik.utils.Utils;
import pl.szczodrzynski.edziennik.utils.models.Date;
@ -513,14 +513,14 @@ public class SettingsNewFragment extends MaterialAboutFragment {
if (app.config.getSync().getInterval() < 60 * 60)
return getString(
R.string.settings_sync_sync_interval_subtext_format,
HomeFragment.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60)
HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60)
);
return getString(
R.string.settings_sync_sync_interval_subtext_format,
HomeFragment.plural(activity, R.plurals.time_till_hours, app.config.getSync().getInterval() / 60 / 60) +
HomeFragmentOld.plural(activity, R.plurals.time_till_hours, app.config.getSync().getInterval() / 60 / 60) +
(app.config.getSync().getInterval() / 60 % 60 == 0 ?
"" :
" " + HomeFragment.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60 % 60)
" " + HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60 % 60)
)
);
}
@ -566,16 +566,16 @@ public class SettingsNewFragment extends MaterialAboutFragment {
syncCardIntervalItem.setOnClickAction(() -> {
List<CharSequence> intervalNames = new ArrayList<>();
if (App.devMode && false) {
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_seconds, 30));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_minutes, 2));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_seconds, 30));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, 2));
}
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_minutes, 30));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_minutes, 45));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 1));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 1)+" "+HomeFragment.plural(activity, R.plurals.time_till_minutes, 30));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 2));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 3));
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 4));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, 30));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, 45));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_hours, 1));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_hours, 1)+" "+ HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, 30));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_hours, 2));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_hours, 3));
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_hours, 4));
List<Integer> intervals = new ArrayList<>();
if (App.devMode && false) {
intervals.add(30);

View File

@ -52,7 +52,7 @@ import pl.szczodrzynski.edziennik.R;
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableBinding;
import pl.szczodrzynski.edziennik.ui.modules.error.ErrorDialog;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment;
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld;
import pl.szczodrzynski.edziennik.utils.SpannableHtmlTagHandler;
import pl.szczodrzynski.edziennik.utils.Themes;
import pl.szczodrzynski.edziennik.utils.Utils;
@ -184,7 +184,7 @@ public class TimetableFragment extends Fragment {
return;
List<LessonFull> lessons = app.db.lessonDao().getAllWeekNow(App.profileId, today.getWeekStart(), today);
displayingDate = HomeFragment.findDateWithLessons(App.profileId, lessons);
displayingDate = HomeFragmentOld.findDateWithLessons(App.profileId, lessons);
pageSelection = 2 + Date.diffDays(displayingDate, today); // DEFAULT HERE
activity.runOnUiThread(() -> {

View File

@ -167,7 +167,7 @@ public class Time implements Comparable<Time> {
long t2millis = t2.getInMillis();
int multiplier = (t1millis > t2millis ? 1 : -1);
Time diff = Time.fromMillis((t1millis - t2millis)*multiplier);
diff.hour -= 1;
// diff.hour -= 1;
return diff;
}
@ -175,7 +175,7 @@ public class Time implements Comparable<Time> {
long t1millis = t1.getInMillis();
long t2millis = t2.getInMillis();
Time sum = Time.fromMillis((t1millis + t2millis));
sum.hour += 1;
// sum.hour += 1;
return sum;
}

View File

@ -1,101 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".HomeFragment">
<!--
~ Copyright (c) Kuba Szczodrzyński 2019-11-23.
-->
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:listitem="@layout/card_home" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".ui.modules.home.HomeFragment">
<LinearLayout
android:id="@+id/cardInsertPoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView
android:id="@+id/nextSync"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
tools:text="TextView" />
<LinearLayout
android:id="@+id/devMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical"
tools:visibility="visible"
tools:ignore="HardcodedText">
<com.google.android.material.button.MaterialButton
android:id="@+id/getLogs"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Save Debug Logs" />
<com.google.android.material.button.MaterialButton
android:id="@+id/librusCaptchaButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Librus Captcha" />
<com.google.android.material.button.MaterialButton
android:id="@+id/runChucker"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Launch Chucker" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.google.android.material.button.MaterialButton
android:id="@+id/mobidziennikMessagesSwitch"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Zmień moduł wiadomości" />
<com.google.android.material.button.MaterialButton
android:id="@+id/composeButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Compose" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/pruneWorkButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Prune finished work" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator>
</layout>

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".HomeFragment">
<pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".ui.modules.home.HomeFragmentOld">
<LinearLayout
android:id="@+id/cardInsertPoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<TextView
android:id="@+id/nextSync"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
tools:text="TextView" />
<LinearLayout
android:id="@+id/devMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical"
tools:visibility="visible"
tools:ignore="HardcodedText">
<com.google.android.material.button.MaterialButton
android:id="@+id/getLogs"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Save Debug Logs" />
<com.google.android.material.button.MaterialButton
android:id="@+id/librusCaptchaButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Librus Captcha" />
<com.google.android.material.button.MaterialButton
android:id="@+id/runChucker"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Launch Chucker" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<com.google.android.material.button.MaterialButton
android:id="@+id/mobidziennikMessagesSwitch"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Zmień moduł wiadomości" />
<com.google.android.material.button.MaterialButton
android:id="@+id/composeButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:text="Compose" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/pruneWorkButton"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Prune finished work" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator>
</layout>

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) Kuba Szczodrzyński 2019-11-23.
-->
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/card_home" />
</pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator>
</layout>