diff --git a/.idea/misc.xml b/.idea/misc.xml index 284dd50e..e2b4e716 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,7 +10,7 @@ - + diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/App.java b/app/src/main/java/pl/szczodrzynski/edziennik/App.java index 37b11cc5..57237a9e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/App.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/App.java @@ -19,7 +19,6 @@ import android.provider.Settings; import android.util.Base64; import android.util.Log; import android.util.Pair; -import android.widget.Toast; import com.evernote.android.job.JobManager; import com.google.android.gms.security.ProviderInstaller; @@ -78,7 +77,6 @@ import pl.szczodrzynski.edziennik.datamodels.ProfileFull; import pl.szczodrzynski.edziennik.models.AppConfig; import pl.szczodrzynski.edziennik.network.NetworkUtils; import pl.szczodrzynski.edziennik.network.TLSSocketFactory; -import pl.szczodrzynski.edziennik.receivers.BootReceiver; import pl.szczodrzynski.edziennik.receivers.JobsCreator; import pl.szczodrzynski.edziennik.sync.SyncJob; import pl.szczodrzynski.edziennik.utils.PermissionChecker; @@ -344,7 +342,7 @@ public class App extends androidx.multidex.MultiDexApplication { .setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_homework)) //.setIcon(getDesktopIconFromIconics(SzkolnyFont.Icon.szf_file_document_edit)) .setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class) - .putExtra("fragmentId", MainActivity.DRAWER_ITEM_HOMEWORKS)) + .putExtra("fragmentId", MainActivity.DRAWER_ITEM_HOMEWORK)) .build(); ShortcutInfo shortcutMessages = new ShortcutInfo.Builder(mContext, "item_messages") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index c6d05ce8..a1808960 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -6,21 +6,14 @@ import android.content.Context import android.content.pm.PackageManager import android.os.Build import android.os.Bundle -import android.util.Log import androidx.core.app.ActivityCompat import com.google.gson.JsonArray -import com.google.gson.JsonNull import com.google.gson.JsonObject -import im.wangchao.mhttp.Response -import im.wangchao.mhttp.callback.JsonCallbackHandler -import im.wangchao.mhttp.callback.TextCallbackHandler -import im.wangchao.mhttp.internal.exception.ResponseFailException import pl.szczodrzynski.edziennik.datamodels.Profile import pl.szczodrzynski.edziennik.datamodels.Teacher import pl.szczodrzynski.navlib.R import pl.szczodrzynski.navlib.crc16 import pl.szczodrzynski.navlib.getColorFromRes -import kotlin.contracts.contract fun List.byId(id: Long) = firstOrNull { it.id == id } fun List.byNameFirstLast(nameFirstLast: String) = firstOrNull { it.name + " " + it.surname == nameFirstLast } @@ -93,4 +86,4 @@ fun Activity.isStoragePermissionGranted(): Boolean { } else { true } -} \ No newline at end of file +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index 62fe8cd9..3a9f77a4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -50,6 +50,7 @@ import pl.szczodrzynski.edziennik.datamodels.Profile import pl.szczodrzynski.edziennik.datamodels.ProfileFull import pl.szczodrzynski.edziennik.dialogs.ChangelogDialog import pl.szczodrzynski.edziennik.fragments.* +import pl.szczodrzynski.edziennik.homework.HomeworkFragment import pl.szczodrzynski.edziennik.login.LoginActivity import pl.szczodrzynski.edziennik.messages.MessagesDetailsFragment import pl.szczodrzynski.edziennik.messages.MessagesFragment @@ -83,7 +84,7 @@ class MainActivity : AppCompatActivity() { const val DRAWER_ITEM_AGENDA = 12 const val DRAWER_ITEM_GRADES = 13 const val DRAWER_ITEM_MESSAGES = 17 - const val DRAWER_ITEM_HOMEWORKS = 14 + const val DRAWER_ITEM_HOMEWORK = 14 const val DRAWER_ITEM_NOTICES = 15 const val DRAWER_ITEM_ATTENDANCES = 16 const val DRAWER_ITEM_ANNOUNCEMENTS = 18 @@ -129,7 +130,7 @@ class MainActivity : AppCompatActivity() { .withBadgeTypeId(TYPE_MESSAGE) .isInDrawer(true) - list += NavTarget(DRAWER_ITEM_HOMEWORKS, R.string.menu_homework, RegisterHomeworksFragment::class) + list += NavTarget(DRAWER_ITEM_HOMEWORK, R.string.menu_homework, HomeworkFragment::class) .withIcon(SzkolnyFont.Icon.szf_file_document_edit) .withBadgeTypeId(TYPE_HOMEWORK) .isInDrawer(true) @@ -522,7 +523,7 @@ class MainActivity : AppCompatActivity() { DRAWER_ITEM_TIMETABLE -> FEATURE_TIMETABLE DRAWER_ITEM_AGENDA -> FEATURE_AGENDA DRAWER_ITEM_GRADES -> FEATURE_GRADES - DRAWER_ITEM_HOMEWORKS -> FEATURE_HOMEWORKS + DRAWER_ITEM_HOMEWORK -> FEATURE_HOMEWORK DRAWER_ITEM_NOTICES -> FEATURE_NOTICES DRAWER_ITEM_ATTENDANCES -> FEATURE_ATTENDANCES DRAWER_ITEM_MESSAGES -> when (MessagesFragment.pageSelection) { @@ -538,7 +539,7 @@ class MainActivity : AppCompatActivity() { DRAWER_ITEM_TIMETABLE -> R.string.sync_feature_timetable DRAWER_ITEM_AGENDA -> R.string.sync_feature_agenda DRAWER_ITEM_GRADES -> R.string.sync_feature_grades - DRAWER_ITEM_HOMEWORKS -> R.string.sync_feature_homeworks + DRAWER_ITEM_HOMEWORK -> R.string.sync_feature_homework DRAWER_ITEM_NOTICES -> R.string.sync_feature_notices DRAWER_ITEM_ATTENDANCES -> R.string.sync_feature_attendances DRAWER_ITEM_MESSAGES -> when (MessagesFragment.pageSelection) { @@ -740,6 +741,9 @@ class MainActivity : AppCompatActivity() { drawer.close() drawer.setSelection(target.id, fireOnClick = false) navView.toolbar.setTitle(target.title ?: target.name) + navView.bottomBar.fabEnable = false + navView.bottomBar.fabExtended = true + navView.bottomBar.setFabOnClickListener(null) Log.d("NavDebug", "Navigating from ${navTarget.fragmentClass?.java?.simpleName} to ${target.fragmentClass?.java?.simpleName}") @@ -848,7 +852,13 @@ class MainActivity : AppCompatActivity() { fun gainAttention() { b.navView.postDelayed({ navView.gainAttentionOnBottomBar() - }, 1000) + }, 2000) + } + + fun collapseFab() { + b.navView.postDelayed({ + navView.bottomBar.fabExtended = false + }, 2000) } /* _____ _ _ diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworksAdapter.java b/app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworkAdapter.java similarity index 56% rename from app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworksAdapter.java rename to app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworkAdapter.java index c66baf98..884fdda1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworksAdapter.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/adapters/HomeworkAdapter.java @@ -24,12 +24,12 @@ import pl.szczodrzynski.edziennik.models.Date; import static pl.szczodrzynski.edziennik.utils.Utils.bs; -public class HomeworksAdapter extends RecyclerView.Adapter { +public class HomeworkAdapter extends RecyclerView.Adapter { private Context context; private List homeworkList; //getting the context and product list with constructor - public HomeworksAdapter(Context mCtx, List homeworkList) { + public HomeworkAdapter(Context mCtx, List homeworkList) { this.context = mCtx; this.homeworkList = homeworkList; } @@ -39,7 +39,7 @@ public class HomeworksAdapter extends RecyclerView.Adapter { app.db.metadataDao().setSeen(App.profileId, homework, true); }); } else { - holder.homeworksItemTopic.setBackground(null); + holder.homeworkItemTopic.setBackground(null); } - holder.homeworksItemEdit.setVisibility((homework.addedManually ? View.VISIBLE : View.GONE)); - holder.homeworksItemEdit.setOnClickListener(v -> { + holder.homeworkItemEdit.setVisibility((homework.addedManually ? View.VISIBLE : View.GONE)); + holder.homeworkItemEdit.setOnClickListener(v -> { new EventManualDialog(context).show(app, homework, null, null, EventManualDialog.DIALOG_HOMEWORK); }); if (homework.sharedBy == null) { - holder.homeworksItemSharedBy.setVisibility(View.GONE); + holder.homeworkItemSharedBy.setVisibility(View.GONE); } else if (homework.sharedByName != null) { - holder.homeworksItemSharedBy.setText(app.getString(R.string.event_shared_by_format, (homework.sharedBy.equals("self") ? app.getString(R.string.event_shared_by_self) : homework.sharedByName))); + holder.homeworkItemSharedBy.setText(app.getString(R.string.event_shared_by_format, (homework.sharedBy.equals("self") ? app.getString(R.string.event_shared_by_self) : homework.sharedByName))); } } @@ -110,23 +110,23 @@ public class HomeworksAdapter extends RecyclerView.Adapter { if (data == null) { - r("finish", "Homeworks"); + r("finish", "Homework"); return; } - JsonArray homeworks = data.get("HomeWorkAssignments").getAsJsonArray(); + JsonArray homeworkList = data.get("HomeWorkAssignments").getAsJsonArray(); //d("Got Grades: "+events.toString()); try { - for (JsonElement homeworkEl : homeworks) { + for (JsonElement homeworkEl : homeworkList) { JsonObject homework = homeworkEl.getAsJsonObject(); JsonElement el; @@ -2787,7 +2787,7 @@ public class Librus implements EdziennikInterface { eventList.add(eventObject); metadataList.add(new Metadata(profileId, Metadata.TYPE_EVENT, eventObject.id, profile.getEmpty(), profile.getEmpty(), addedDate.getInMillis())); } - r("finish", "Homeworks"); + r("finish", "Homework"); } catch (Exception e) { finishWithError(new AppError(TAG, 2648, CODE_OTHER, e, data)); @@ -3377,7 +3377,7 @@ public class Librus implements EdziennikInterface { configurableEndpoints.put("Grades", new Endpoint("Grades",true, false, profile.getChangedEndpoints())); configurableEndpoints.put("PointGrades", new Endpoint("PointGrades",true, false, profile.getChangedEndpoints())); configurableEndpoints.put("Events", new Endpoint("Events",true, false, profile.getChangedEndpoints())); - configurableEndpoints.put("Homeworks", new Endpoint("Homeworks",true, false, profile.getChangedEndpoints())); + configurableEndpoints.put("Homework", new Endpoint("Homework",true, false, profile.getChangedEndpoints())); configurableEndpoints.put("LuckyNumbers", new Endpoint("LuckyNumbers",true, false, profile.getChangedEndpoints())); configurableEndpoints.put("Notices", new Endpoint("Notices",true, false, profile.getChangedEndpoints())); configurableEndpoints.put("Attendances", new Endpoint("Attendances",true, false, profile.getChangedEndpoints())); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/Mobidziennik.java b/app/src/main/java/pl/szczodrzynski/edziennik/api/Mobidziennik.java index 7df269d6..14a1e168 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/Mobidziennik.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/Mobidziennik.java @@ -609,7 +609,7 @@ public class Mobidziennik implements EdziennikInterface { processEvents(table); } if (i == 23) { - processHomeworks(table); + processHomework(table); } if (i == 24) { processTimetable(table); @@ -1891,11 +1891,11 @@ public class Mobidziennik implements EdziennikInterface { } } - private void processHomeworks(String table) + private void processHomework(String table) { - String[] homeworks = table.split("\n"); + String[] homeworkList = table.split("\n"); Date today = Date.getToday(); - for (String homeworkStr: homeworks) + for (String homeworkStr: homeworkList) { if (homeworkStr.isEmpty()) { continue; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/Vulcan.java b/app/src/main/java/pl/szczodrzynski/edziennik/api/Vulcan.java index 6e76974e..85893a62 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/Vulcan.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/Vulcan.java @@ -108,7 +108,7 @@ public class Vulcan implements EdziennikInterface { private static final String ENDPOINT_GRADES = "mobile-api/Uczen.v3.Uczen/Oceny"; private static final String ENDPOINT_GRADES_PROPOSITIONS = "mobile-api/Uczen.v3.Uczen/OcenyPodsumowanie"; private static final String ENDPOINT_EVENTS = "mobile-api/Uczen.v3.Uczen/Sprawdziany"; - private static final String ENDPOINT_HOMEWORKS = "mobile-api/Uczen.v3.Uczen/ZadaniaDomowe"; + private static final String ENDPOINT_HOMEWORK = "mobile-api/Uczen.v3.Uczen/ZadaniaDomowe"; private static final String ENDPOINT_NOTICES = "mobile-api/Uczen.v3.Uczen/UwagiUcznia"; private static final String ENDPOINT_ATTENDANCES = "mobile-api/Uczen.v3.Uczen/Frekwencje"; private static final String ENDPOINT_MESSAGES_RECEIVED = "mobile-api/Uczen.v3.Uczen/WiadomosciOdebrane"; @@ -259,7 +259,7 @@ public class Vulcan implements EdziennikInterface { targetEndpoints.add("Grades"); targetEndpoints.add("ProposedGrades"); targetEndpoints.add("Events"); - targetEndpoints.add("Homeworks"); + targetEndpoints.add("Homework"); targetEndpoints.add("Notices"); targetEndpoints.add("Attendances"); targetEndpoints.add("MessagesInbox"); @@ -297,8 +297,8 @@ public class Vulcan implements EdziennikInterface { targetEndpoints.add("Grades"); targetEndpoints.add("ProposedGrades"); break; - case FEATURE_HOMEWORKS: - targetEndpoints.add("Homeworks"); + case FEATURE_HOMEWORK: + targetEndpoints.add("Homework"); break; case FEATURE_NOTICES: targetEndpoints.add("Notices"); @@ -380,8 +380,8 @@ public class Vulcan implements EdziennikInterface { case "Events": getEvents(); break; - case "Homeworks": - getHomeworks(); + case "Homework": + getHomework(); break; case "Notices": getNotices(); @@ -1374,7 +1374,7 @@ public class Vulcan implements EdziennikInterface { }); } - private void getHomeworks() { + private void getHomework() { callback.onActionStarted(R.string.sync_action_syncing_homework); JsonObject json = new JsonObject(); json.addProperty("DataPoczatkowa", profile.getEmpty() ? getCurrentSemesterStartDate().getStringY_m_d() : oneMonthBack.getStringY_m_d()); @@ -1382,10 +1382,10 @@ public class Vulcan implements EdziennikInterface { json.addProperty("IdOddzial", studentClassId); json.addProperty("IdUczen", studentId); json.addProperty("IdOkresKlasyfikacyjny", studentSemesterId); - apiRequest(schoolSymbol+"/"+ENDPOINT_HOMEWORKS, json, result -> { - JsonArray homeworks = result.getAsJsonArray("Data"); + apiRequest(schoolSymbol+"/"+ ENDPOINT_HOMEWORK, json, result -> { + JsonArray homeworkList = result.getAsJsonArray("Data"); - for (JsonElement homeworkEl: homeworks) { + for (JsonElement homeworkEl: homeworkList) { JsonObject homework = homeworkEl.getAsJsonObject(); int id = homework.get("Id").getAsInt(); @@ -1419,7 +1419,7 @@ public class Vulcan implements EdziennikInterface { eventList.add(eventObject); metadataList.add(new Metadata(profileId, Metadata.TYPE_HOMEWORK, eventObject.id, profile.getEmpty(), profile.getEmpty(), System.currentTimeMillis())); } - r("finish", "Homeworks"); + r("finish", "Homework"); }); } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/interfaces/EdziennikInterface.java b/app/src/main/java/pl/szczodrzynski/edziennik/api/interfaces/EdziennikInterface.java index d7bcde5f..2d33d515 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/interfaces/EdziennikInterface.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/interfaces/EdziennikInterface.java @@ -34,7 +34,7 @@ public interface EdziennikInterface { int FEATURE_TIMETABLE = 1; int FEATURE_AGENDA = 2; int FEATURE_GRADES = 3; - int FEATURE_HOMEWORKS = 4; + int FEATURE_HOMEWORK = 4; int FEATURE_NOTICES = 5; int FEATURE_ATTENDANCES = 6; int FEATURE_MESSAGES_INBOX = 7; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/Constants.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/Constants.kt index 3aae0da1..0125de4d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/Constants.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/Constants.kt @@ -4,7 +4,7 @@ const val FEATURE_ALL = 0 const val FEATURE_TIMETABLE = 1 const val FEATURE_AGENDA = 2 const val FEATURE_GRADES = 3 -const val FEATURE_HOMEWORKS = 4 +const val FEATURE_HOMEWORK = 4 const val FEATURE_NOTICES = 5 const val FEATURE_ATTENDANCES = 6 const val FEATURE_MESSAGES_INBOX = 7 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/MetadataDao.java b/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/MetadataDao.java index fdc61ecb..321ee89b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/MetadataDao.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/MetadataDao.java @@ -202,7 +202,7 @@ public abstract class MetadataDao { public abstract void deleteUnusedEvents(int profileId); @Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_HOMEWORK+" AND thingId NOT IN (SELECT eventId FROM events WHERE profileId = :profileId AND eventType = -1);") - public abstract void deleteUnusedHomeworks(int profileId); + public abstract void deleteUnusedHomework(int profileId); @Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_LESSON_CHANGE+" AND thingId NOT IN (SELECT lessonChangeId FROM lessonChanges WHERE profileId = :profileId);") public abstract void deleteUnusedLessonChanges(int profileId); @@ -219,9 +219,9 @@ public abstract class MetadataDao { deleteUnusedNotices(profileId); deleteUnusedAttendances(profileId); deleteUnusedEvents(profileId); - deleteUnusedHomeworks(profileId); + deleteUnusedHomework(profileId); deleteUnusedLessonChanges(profileId); deleteUnusedAnnouncements(profileId); deleteUnusedMessages(profileId); } -} \ No newline at end of file +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/ProfileFull.kt b/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/ProfileFull.kt index a221849a..037c29cc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/ProfileFull.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/datamodels/ProfileFull.kt @@ -7,7 +7,7 @@ import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_AGENDA import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_ANNOUNCEMENTS import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_ATTENDANCES import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_GRADES -import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORKS +import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORK import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_NOTICES import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE @@ -50,7 +50,7 @@ class ProfileFull : Profile { fragmentIds.add(DRAWER_ITEM_AGENDA) fragmentIds.add(DRAWER_ITEM_GRADES) fragmentIds.add(DRAWER_ITEM_MESSAGES) - fragmentIds.add(DRAWER_ITEM_HOMEWORKS) + fragmentIds.add(DRAWER_ITEM_HOMEWORK) fragmentIds.add(DRAWER_ITEM_NOTICES) fragmentIds.add(DRAWER_ITEM_ATTENDANCES) return fragmentIds @@ -61,7 +61,7 @@ class ProfileFull : Profile { fragmentIds.add(DRAWER_ITEM_AGENDA) fragmentIds.add(DRAWER_ITEM_GRADES) fragmentIds.add(DRAWER_ITEM_MESSAGES) - fragmentIds.add(DRAWER_ITEM_HOMEWORKS) + fragmentIds.add(DRAWER_ITEM_HOMEWORK) fragmentIds.add(DRAWER_ITEM_NOTICES) fragmentIds.add(DRAWER_ITEM_ATTENDANCES) fragmentIds.add(DRAWER_ITEM_ANNOUNCEMENTS) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/fragments/RegisterHomeworksFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/fragments/RegisterHomeworksFragment.java deleted file mode 100644 index cb49eabb..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/fragments/RegisterHomeworksFragment.java +++ /dev/null @@ -1,127 +0,0 @@ -package pl.szczodrzynski.edziennik.fragments; - -import android.os.AsyncTask; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.databinding.DataBindingUtil; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; - -import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial; - -import pl.szczodrzynski.edziennik.App; -import pl.szczodrzynski.edziennik.R; -import pl.szczodrzynski.edziennik.MainActivity; -import pl.szczodrzynski.edziennik.adapters.HomeworksAdapter; -import pl.szczodrzynski.edziennik.databinding.FragmentRegisterHomeworksBinding; -import pl.szczodrzynski.edziennik.datamodels.Metadata; -import pl.szczodrzynski.edziennik.dialogs.EventManualDialog; -import pl.szczodrzynski.edziennik.models.Date; -import pl.szczodrzynski.edziennik.utils.Themes; -import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem; -import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem; - -import static pl.szczodrzynski.edziennik.datamodels.Event.TYPE_HOMEWORK; - -public class RegisterHomeworksFragment extends Fragment { - - private App app = null; - private MainActivity activity = null; - private FragmentRegisterHomeworksBinding b = null; - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - activity = (MainActivity) getActivity(); - if (getActivity() == null || getContext() == null) - return null; - app = (App) activity.getApplication(); - getContext().getTheme().applyStyle(Themes.INSTANCE.getAppTheme(), true); - 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_register_homeworks, container, false); - b.refreshLayout.setParent(activity.getSwipeRefreshLayout()); - return b.getRoot(); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - if (app == null || app.profile == null || activity == null || b == null || !isAdded()) - return; - - activity.getBottomSheet().prependItems( - new BottomSheetPrimaryItem(true) - .withTitle(R.string.menu_add_event) - .withDescription(R.string.menu_add_event_desc) - .withIcon(CommunityMaterial.Icon.cmd_calendar_plus) - .withOnClickListener(v3 -> { - activity.getBottomSheet().close(); - new EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK); - }), - new BottomSheetSeparatorItem(true), - new BottomSheetPrimaryItem(true) - .withTitle(R.string.menu_mark_as_read) - .withIcon(CommunityMaterial.Icon.cmd_eye_check) - .withOnClickListener(v3 -> { - activity.getBottomSheet().close(); - AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, Metadata.TYPE_HOMEWORK, true)); - Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show(); - }) - ); - activity.gainAttention(); - - /*b.refreshLayout.setOnRefreshListener(() -> { - activity.syncCurrentFeature(MainActivity.DRAWER_ITEM_HOMEWORKS, b.refreshLayout); - });*/ - - LinearLayoutManager linearLayoutCurrentManager = new LinearLayoutManager(getContext()); - linearLayoutCurrentManager.setReverseLayout(false); - linearLayoutCurrentManager.setStackFromEnd(false); - LinearLayoutManager linearLayoutPastManager = new LinearLayoutManager(getContext()); - linearLayoutPastManager.setReverseLayout(true); - linearLayoutPastManager.setStackFromEnd(true); - - b.homeworksCurrentView.setHasFixedSize(true); - b.homeworksCurrentView.setLayoutManager(linearLayoutCurrentManager); - b.homeworksPastView.setHasFixedSize(true); - b.homeworksPastView.setLayoutManager(linearLayoutPastManager); - - app.db.eventDao().getAllByType(App.profileId, TYPE_HOMEWORK, "eventDate >= '"+Date.getToday().getStringY_m_d()+"'").observe(this, currentList -> { - if (app == null || app.profile == null || activity == null || b == null || !isAdded()) - return; - - if (currentList != null && currentList.size() > 0) { - HomeworksAdapter adapter = new HomeworksAdapter(getContext(), currentList); - b.homeworksCurrentView.setAdapter(adapter); - b.homeworksCurrentView.setVisibility(View.VISIBLE); - b.homeworksCurrentNoData.setVisibility(View.GONE); - } - else { - b.homeworksCurrentView.setVisibility(View.GONE); - b.homeworksCurrentNoData.setVisibility(View.VISIBLE); - } - }); - - app.db.eventDao().getAllByType(App.profileId, TYPE_HOMEWORK, "eventDate < '"+Date.getToday().getStringY_m_d()+"'").observe(this, pastList -> { - if (app == null || app.profile == null || activity == null || b == null || !isAdded()) - return; - - if (pastList != null && pastList.size() > 0) { - HomeworksAdapter adapter = new HomeworksAdapter(getContext(), pastList); - b.homeworksPastView.setAdapter(adapter); - b.homeworksPastView.setVisibility(View.VISIBLE); - b.homeworksPastNoData.setVisibility(View.GONE); - } - else { - b.homeworksPastView.setVisibility(View.GONE); - b.homeworksPastNoData.setVisibility(View.VISIBLE); - } - }); - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/fragments/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/fragments/SettingsNewFragment.java index df163e34..bde0ecd7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/fragments/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/fragments/SettingsNewFragment.java @@ -350,7 +350,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { buttonIds.add(MainActivity.DRAWER_ITEM_AGENDA); buttonIds.add(MainActivity.DRAWER_ITEM_GRADES); buttonIds.add(MainActivity.DRAWER_ITEM_MESSAGES); - buttonIds.add(MainActivity.DRAWER_ITEM_HOMEWORKS); + buttonIds.add(MainActivity.DRAWER_ITEM_HOMEWORK); buttonIds.add(MainActivity.DRAWER_ITEM_NOTICES); buttonIds.add(MainActivity.DRAWER_ITEM_ATTENDANCES); buttonIds.add(MainActivity.DRAWER_ITEM_ANNOUNCEMENTS); @@ -1091,8 +1091,8 @@ public class SettingsNewFragment extends MaterialAboutFragment { case "Events": stringRes = R.string.settings_sync_customize_endpoint_events; break; - case "Homeworks": - stringRes = R.string.settings_sync_customize_endpoint_homeworks; + case "Homework": + stringRes = R.string.settings_sync_customize_endpoint_homework; break; case "LuckyNumber": case "LuckyNumbers": diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkDate.kt b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkDate.kt new file mode 100644 index 00000000..0aacdf94 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkDate.kt @@ -0,0 +1,8 @@ +package pl.szczodrzynski.edziennik.homework + +class HomeworkDate { + companion object { + val CURRENT = 0 + val PAST = 1 + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkFragment.kt new file mode 100644 index 00000000..891ddea2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkFragment.kt @@ -0,0 +1,107 @@ +package pl.szczodrzynski.edziennik.homework + +import android.os.AsyncTask +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.fragment.app.Fragment +import androidx.viewpager.widget.ViewPager +import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial +import kotlinx.android.synthetic.main.activity_szkolny.* +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.databinding.FragmentHomeworkBinding +import pl.szczodrzynski.edziennik.datamodels.Metadata +import pl.szczodrzynski.edziennik.dialogs.EventManualDialog +import pl.szczodrzynski.edziennik.messages.MessagesFragment +import pl.szczodrzynski.edziennik.utils.Themes +import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem +import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem + +class HomeworkFragment : Fragment() { + companion object { + var pageSelection = 0 + } + + private lateinit var app: App + private lateinit var activity: MainActivity + private lateinit var b: FragmentHomeworkBinding + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + activity = (getActivity() as MainActivity?) ?: return null + if (context == null) + return null + app = activity.application as App + context!!.theme.applyStyle(Themes.appTheme, true) + if (app.profile == null) + return inflater.inflate(R.layout.fragment_loading, container, false) + // activity, context and profile is valid + b = FragmentHomeworkBinding.inflate(inflater) + b.refreshLayout.setParent(activity.swipeRefreshLayout) + return b.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + // TODO check if app, activity, b can be null + if (app.profile == null || !isAdded) + return + + activity.bottomSheet.prependItems( + BottomSheetPrimaryItem(true) + .withTitle(R.string.menu_add_event) + .withDescription(R.string.menu_add_event_desc) + .withIcon(CommunityMaterial.Icon.cmd_calendar_plus) + .withOnClickListener(View.OnClickListener { + activity.bottomSheet.close() + EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK) + }), + BottomSheetSeparatorItem(true), + BottomSheetPrimaryItem(true) + .withTitle(R.string.menu_mark_as_read) + .withIcon(CommunityMaterial.Icon.cmd_eye_check) + .withOnClickListener(View.OnClickListener { + activity.bottomSheet.close() + AsyncTask.execute { app.db.metadataDao().setAllSeen(App.profileId, Metadata.TYPE_HOMEWORK, true) } + Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show() + })) + + b.viewPager.adapter = MessagesFragment.Adapter(childFragmentManager).also { adapter -> + adapter.addFragment(HomeworkListFragment().also { fragment -> + fragment.arguments = Bundle().also { args -> + args.putInt("homeworkDate", HomeworkDate.CURRENT) + } + }, getString(R.string.homework_tab_current)) + + adapter.addFragment(HomeworkListFragment().also { fragment -> + fragment.arguments = Bundle().also { args -> + args.putInt("homeworkDate", HomeworkDate.PAST) + } + }, getString(R.string.homework_tab_past)) + } + + b.viewPager.currentItem = pageSelection + b.viewPager.clearOnPageChangeListeners() + b.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) {} + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} + override fun onPageSelected(position: Int) { + pageSelection = position + } + }) + + b.tabLayout.setupWithViewPager(b.viewPager) + + activity.navView.bottomBar.fabEnable = true + activity.navView.bottomBar.fabExtendedText = "Dodaj nowe" + activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon2.cmd_plus + activity.navView.setFabOnClickListener(View.OnClickListener { + EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK) + }) + + activity.gainAttention() + activity.collapseFab() + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkListFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkListFragment.kt new file mode 100644 index 00000000..7fd3f537 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/homework/HomeworkListFragment.kt @@ -0,0 +1,79 @@ +package pl.szczodrzynski.edziennik.homework + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import kotlinx.android.synthetic.main.activity_szkolny.* +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.MainActivity +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.adapters.HomeworkAdapter +import pl.szczodrzynski.edziennik.databinding.HomeworkListBinding +import pl.szczodrzynski.edziennik.datamodels.Event +import pl.szczodrzynski.edziennik.getInt +import pl.szczodrzynski.edziennik.models.Date +import pl.szczodrzynski.edziennik.utils.Themes + +class HomeworkListFragment : Fragment() { + + private lateinit var app: App + private lateinit var activity: MainActivity + private lateinit var b: HomeworkListBinding + + private var homeworkDate = HomeworkDate.CURRENT + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + activity = (getActivity() as MainActivity?) ?: return null + if (context == null) + return null + app = activity.application as App + context!!.theme.applyStyle(Themes.appTheme, true) + if (app.profile == null) + return inflater.inflate(R.layout.fragment_loading, container, false) + // activity, context and profile is valid + b = HomeworkListBinding.inflate(inflater) + return b.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + // TODO check if app, activity, b can be null + if (app.profile == null || !isAdded) + return + + if (arguments != null) { + homeworkDate = arguments.getInt("homeworkDate", HomeworkDate.CURRENT) + } + + val layoutManager = LinearLayoutManager(context) + layoutManager.reverseLayout = false + layoutManager.stackFromEnd = false + + b.homeworkView.setHasFixedSize(true) + b.homeworkView.layoutManager = layoutManager + + val filter = when(homeworkDate) { + HomeworkDate.CURRENT -> "eventDate > '" + Date.getToday().stringY_m_d + "'" + else -> "eventDate <= '" + Date.getToday().stringY_m_d + "'" + } + + app.db.eventDao() + .getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter) + .observe(this, Observer { homeworkList -> + if (app.profile == null || !isAdded) return@Observer + + if (homeworkList != null && homeworkList.size > 0) { + val adapter = HomeworkAdapter(context, homeworkList) + b.homeworkView.adapter = adapter + b.homeworkView.visibility = View.VISIBLE + b.homeworkNoData.visibility = View.GONE + } else { + b.homeworkView.visibility = View.GONE + b.homeworkNoData.visibility = View.VISIBLE + } + }) + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/messages/MessagesListFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/messages/MessagesListFragment.java index 07a3a8a6..2d4b9b9f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/messages/MessagesListFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/messages/MessagesListFragment.java @@ -76,7 +76,6 @@ public class MessagesListFragment extends Fragment { return inflater.inflate(R.layout.fragment_loading, container, false); // activity, context and profile is valid b = DataBindingUtil.inflate(inflater, R.layout.messages_list, container, false); - b.refreshLayout.setParent(activity.getSwipeRefreshLayout()); return b.getRoot(); } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/models/AppConfig.java b/app/src/main/java/pl/szczodrzynski/edziennik/models/AppConfig.java index 05a6d362..89335486 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/models/AppConfig.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/models/AppConfig.java @@ -38,7 +38,7 @@ public class AppConfig { miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_AGENDA); miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_GRADES); miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_MESSAGES); - miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_HOMEWORKS); + miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_HOMEWORK); miniDrawerButtonIds.add(MainActivity.DRAWER_ITEM_SETTINGS); fcmToken = ""; fcmTokens = new TreeMap<>(); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java index 7c55629e..2b56b9bc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/sync/MyFirebaseMessagingService.java @@ -280,7 +280,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { app.notifier.add(new Notification(app.getContext(), app.getString((oldEvent == null ? R.string.notification_shared_event_format : R.string.notification_shared_event_modified_format), event.sharedByName, eventType == null ? "wydarzenie" : eventType.name, event.eventDate.getFormattedString(), event.topic)) .withProfileData(profile.getId(), profile.getName()) .withType(event.type == TYPE_HOMEWORK ? Notification.TYPE_NEW_SHARED_HOMEWORK : Notification.TYPE_NEW_SHARED_EVENT) - .withFragmentRedirect(event.type == TYPE_HOMEWORK ? MainActivity.DRAWER_ITEM_HOMEWORKS : MainActivity.DRAWER_ITEM_AGENDA) + .withFragmentRedirect(event.type == TYPE_HOMEWORK ? MainActivity.DRAWER_ITEM_HOMEWORK : MainActivity.DRAWER_ITEM_AGENDA) .withLongExtra("eventDate", event.eventDate.getValue()) ); d(TAG, "Finishing adding event " + event); @@ -299,7 +299,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { app.notifier.add(new Notification(app.getContext(), app.getString(R.string.notification_shared_event_removed_format, oldEvent.sharedByName, oldEvent.typeName, oldEvent.eventDate.getFormattedString(), oldEvent.topic)) .withProfileData(profile.getId(), profile.getName()) .withType(oldEvent.type == TYPE_HOMEWORK ? Notification.TYPE_NEW_SHARED_HOMEWORK : Notification.TYPE_NEW_SHARED_EVENT) - .withFragmentRedirect(oldEvent.type == TYPE_HOMEWORK ? MainActivity.DRAWER_ITEM_HOMEWORKS : MainActivity.DRAWER_ITEM_AGENDA) + .withFragmentRedirect(oldEvent.type == TYPE_HOMEWORK ? MainActivity.DRAWER_ITEM_HOMEWORK : MainActivity.DRAWER_ITEM_AGENDA) .withLongExtra("eventDate", oldEvent.eventDate.getValue()) ); app.db.eventDao().remove(oldEvent); diff --git a/app/src/main/res/layout/fragment_homework.xml b/app/src/main/res/layout/fragment_homework.xml new file mode 100644 index 00000000..91d904be --- /dev/null +++ b/app/src/main/res/layout/fragment_homework.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_register_homeworks.xml b/app/src/main/res/layout/fragment_register_homeworks.xml deleted file mode 100644 index 1bca5365..00000000 --- a/app/src/main/res/layout/fragment_register_homeworks.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/homework_list.xml b/app/src/main/res/layout/homework_list.xml new file mode 100644 index 00000000..bfcc4960 --- /dev/null +++ b/app/src/main/res/layout/homework_list.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/messages_list.xml b/app/src/main/res/layout/messages_list.xml index 2021cf68..e3eca8fe 100644 --- a/app/src/main/res/layout/messages_list.xml +++ b/app/src/main/res/layout/messages_list.xml @@ -5,20 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - + android:layout_height="match_parent" + android:clipChildren="false" + android:transitionGroup="false" + tools:listitem="@layout/messages_item" + tools:targetApi="lollipop" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/row_homeworks_item.xml b/app/src/main/res/layout/row_homework_item.xml similarity index 91% rename from app/src/main/res/layout/row_homeworks_item.xml rename to app/src/main/res/layout/row_homework_item.xml index a7067e77..629bac4a 100644 --- a/app/src/main/res/layout/row_homeworks_item.xml +++ b/app/src/main/res/layout/row_homework_item.xml @@ -7,7 +7,7 @@ android:orientation="vertical"> - \ No newline at end of file + diff --git a/app/src/main/res/navigation/nav_main.xml b/app/src/main/res/navigation/nav_main.xml deleted file mode 100644 index b161f2f4..00000000 --- a/app/src/main/res/navigation/nav_main.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index c005d191..9d105afe 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -607,7 +607,7 @@ Classrooms Events/agenda Grades - Homework + Homework Lucky number Messages - received Messages - sent @@ -753,7 +753,7 @@ Syncing announcements… Syncing attendances… Syncing grades… - Syncing homeworks… + Syncing homework… Syncing received messages… Syncing sent messages… Syncing notices… @@ -827,4 +827,4 @@ yesterday You\'re offline. Try enabling Wi-Fi or mobile data. Internet connection - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e0f6a927..6b2a4514 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -313,8 +313,8 @@ Edytuj Brak poprzednich zadań domowych. Poprzednie zadania - %s, %s - %s %s + %s, %s + %s %s Zgadzam się Nie zgadzam się Nieprawidłowy format @@ -652,7 +652,7 @@ Sale lekcyjne Wydarzenia/terminarz Oceny - Zadania domowe + Zadania domowe Szczęśliwy numerek Wiadomości odebrane Wiadomości wysłane @@ -800,7 +800,7 @@ Pobieram tablicę ogłoszeń… Pobieram obecności… Pobieram oceny… - Pobieram zadania domowe… + Pobieram zadania domowe… Pobieram wiadomości odebrane… Pobieram wiadomości wysłane… Pobieram uwagi… @@ -909,4 +909,7 @@ Dołącz do naszego serwera Discord! Debugowanie Pobieranie dni wolnych szkoły + Aktualne + Minione + Brak zadań domowych. diff --git a/build.gradle b/build.gradle index aadf871a..93c1e118 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ buildscript { iconics : "4.0.1-b02", font_cmd : "3.5.95.1-kotlin", - navlib : "84d6447887", + navlib : "e4ad01dc87", gifdrawable : "1.2.15" ]