forked from github/szkolny
[Deprecated] Remove deprecated home fragment.
This commit is contained in:
parent
26eb2e4381
commit
aafa87c661
@ -912,3 +912,5 @@ fun String.base64DecodeToString(): String {
|
||||
}
|
||||
|
||||
fun CheckBox.trigger() { isChecked = !isChecked }
|
||||
|
||||
fun Context.plural(@PluralsRes resId: Int, value: Int): String = resources.getQuantityString(resId, value, value)
|
||||
|
@ -1,515 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.home;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.work.WorkManager;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.chuckerteam.chucker.api.Chucker;
|
||||
import com.hypertrack.hyperlog.HyperLog;
|
||||
import com.mikepenz.iconics.IconicsColor;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.mikepenz.iconics.IconicsSize;
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||
import com.mikepenz.iconics.typeface.library.szkolny.font.SzkolnyFont;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.BuildConfig;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject;
|
||||
import pl.szczodrzynski.edziennik.databinding.CardUpdateBinding;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentHomeOldBinding;
|
||||
import pl.szczodrzynski.edziennik.receivers.BootReceiver;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginLibrusCaptchaActivity;
|
||||
import pl.szczodrzynski.edziennik.utils.Colors;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
import pl.szczodrzynski.edziennik.utils.models.ItemGradesSubjectModel;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
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.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;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER2_PROPOSED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_YEAR_FINAL;
|
||||
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 HomeFragmentOld extends Fragment {
|
||||
private static final String TAG = "HomeFragmentOld";
|
||||
private App app = null;
|
||||
private MainActivity activity = null;
|
||||
private FragmentHomeOldBinding 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_home_old, 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;
|
||||
|
||||
b.devMode.setVisibility(App.devMode ? View.VISIBLE : View.GONE);
|
||||
|
||||
b.composeButton.setOnClickListener((v -> {
|
||||
}));
|
||||
|
||||
b.pruneWorkButton.setOnClickListener((v -> WorkManager.getInstance(app).pruneWork()));
|
||||
|
||||
b.runChucker.setOnClickListener((v -> {
|
||||
startActivity(Chucker.getLaunchIntent(activity, 1));
|
||||
}));
|
||||
|
||||
b.librusCaptchaButton.setOnClickListener((v -> {
|
||||
startActivity(new Intent(activity, LoginLibrusCaptchaActivity.class));
|
||||
}));
|
||||
|
||||
b.getLogs.setOnClickListener((v -> {
|
||||
File logs = HyperLog.getDeviceLogsInFile(activity, true);
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
if(logs.exists()) {
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+logs.getAbsolutePath()));
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Share debug logs");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, "Share debug logs");
|
||||
startActivity(Intent.createChooser(intent, "Share debug logs"));
|
||||
}
|
||||
}));
|
||||
|
||||
//((TextView)v.findViewById(R.id.nextSync)).setText(getString(R.string.next_sync_format,Time.fromMillis(app.appJobs.syncJobTime).getStringHMS()));
|
||||
|
||||
|
||||
|
||||
LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
ViewGroup insertPoint = b.cardInsertPoint;
|
||||
assert layoutInflater != null;
|
||||
|
||||
if (app.profile.getLoginStoreType() == LOGIN_TYPE_MOBIDZIENNIK && app.appConfig.mobidziennikOldMessages == -1) {
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title("Nowy moduł wiadomości")
|
||||
.content("Czy chcesz używać nowego modułu wiadomości?\n\nObejmuje lepsze powiadomienia, działa szybciej, pozwala na przeglądanie pobranych wiadomości bez internetu.\n\nNowy moduł (jeszcze) nie pozwala na wysyłanie wiadomości.")
|
||||
.positiveText(R.string.yes)
|
||||
.negativeText(R.string.no)
|
||||
.onPositive(((dialog, which) -> {
|
||||
if (app.appConfig.mobidziennikOldMessages != 0) {
|
||||
// need to change old to new
|
||||
app.appConfig.mobidziennikOldMessages = 0;
|
||||
app.saveConfig("mobidziennikOldMessages");
|
||||
MainActivity.Companion.setUseOldMessages(false);
|
||||
activity.loadProfile(App.profileId);
|
||||
}
|
||||
}))
|
||||
.onNegative(((dialog, which) -> {
|
||||
if (app.appConfig.mobidziennikOldMessages != 1) {
|
||||
// need to change from ?? to old
|
||||
app.appConfig.mobidziennikOldMessages = 1;
|
||||
app.saveConfig("mobidziennikOldMessages");
|
||||
MainActivity.Companion.setUseOldMessages(true);
|
||||
activity.loadProfile(App.profileId);
|
||||
}
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
|
||||
b.mobidziennikMessagesSwitch.setVisibility(app.profile.getLoginStoreType() == LOGIN_TYPE_MOBIDZIENNIK ? View.VISIBLE : View.GONE);
|
||||
b.mobidziennikMessagesSwitch.setOnClickListener((v -> {
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title("Nowy moduł wiadomości")
|
||||
.content("Czy chcesz używać nowego modułu wiadomości?\n\nObejmuje lepsze powiadomienia, działa szybciej, pozwala na przeglądanie pobranych wiadomości bez internetu.\n\nNowy moduł (jeszcze) nie pozwala na wysyłanie wiadomości.")
|
||||
.positiveText(R.string.yes)
|
||||
.negativeText(R.string.no)
|
||||
.onPositive(((dialog, which) -> {
|
||||
if (app.appConfig.mobidziennikOldMessages != 0) {
|
||||
// need to change old to new
|
||||
app.appConfig.mobidziennikOldMessages = 0;
|
||||
app.saveConfig("mobidziennikOldMessages");
|
||||
MainActivity.Companion.setUseOldMessages(false);
|
||||
activity.loadProfile(App.profileId);
|
||||
}
|
||||
}))
|
||||
.onNegative(((dialog, which) -> {
|
||||
if (app.appConfig.mobidziennikOldMessages != 1) {
|
||||
// need to change from ?? to old
|
||||
app.appConfig.mobidziennikOldMessages = 1;
|
||||
app.saveConfig("mobidziennikOldMessages");
|
||||
MainActivity.Companion.setUseOldMessages(true);
|
||||
activity.loadProfile(App.profileId);
|
||||
}
|
||||
}))
|
||||
.show();
|
||||
}));
|
||||
|
||||
/*if (!app.profile.loggedIn) {
|
||||
View cardLoginRoot = layoutInflater.inflate(R.layout.card_login, null);
|
||||
|
||||
CardView cardLogin = cardLoginRoot.findViewById(R.id.cardLogin);
|
||||
cardLogin.setVisibility(app.profile.loggedIn ? View.GONE : View.VISIBLE);
|
||||
Button cardLoginButton = cardLoginRoot.findViewById(R.id.cardLoginButton);
|
||||
buttonAddDrawable(c, cardLoginButton, CommunityMaterial.Icon.cmd_arrow_right);
|
||||
cardLoginButton.setOnClickListener((v1 -> {
|
||||
new Handler().postDelayed(() -> {
|
||||
a.runOnUiThread(() -> {
|
||||
Intent i = new Intent("android.intent.action.MAIN")
|
||||
.putExtra(MainActivity.ACTION_CHANGE_CURRENT_VIEW, "yes, sure")
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_SETTINGS)
|
||||
.putExtra("settingsPage", SettingsFragment.PAGE_REGISTER);
|
||||
app.getContext().sendBroadcast(i);
|
||||
});
|
||||
}, 100);
|
||||
}));
|
||||
|
||||
insertPoint.addView(cardLoginRoot, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
if (app.appConfig.updateVersion != null && !app.appConfig.updateVersion.equals("")) {
|
||||
if (app.appConfig.updateVersion.equals(BuildConfig.VERSION_NAME)) {
|
||||
app.appConfig.updateVersion = "";
|
||||
app.saveConfig("updateVersion");
|
||||
}
|
||||
else {
|
||||
CardUpdateBinding b;
|
||||
b = DataBindingUtil.inflate(layoutInflater, R.layout.card_update, insertPoint, false);
|
||||
insertPoint.addView(b.getRoot());
|
||||
|
||||
b.cardUpdateText.setText(getString(R.string.card_update_text_format, BuildConfig.VERSION_NAME, app.appConfig.updateVersion));
|
||||
buttonAddDrawable(activity, b.cardUpdateButton, CommunityMaterial.Icon.cmd_arrow_right);
|
||||
b.cardUpdateButton.setOnClickListener((v1 -> {
|
||||
if (UPDATES_ON_PLAY_STORE) {
|
||||
Utils.openGooglePlay(activity, "pl.szczodrzynski.edziennik");
|
||||
}
|
||||
else {
|
||||
BootReceiver.update_url = app.appConfig.updateUrl;
|
||||
BootReceiver.update_filename = app.appConfig.updateFilename;
|
||||
BootReceiver.update_download_id = BootReceiver.downloadFile(app);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// timetableCard = new HomeTimetableCardOld(app, activity, this, layoutInflater, insertPoint);
|
||||
// timetableCard.run();
|
||||
|
||||
configCardGrades(activity, layoutInflater, activity, insertPoint);
|
||||
|
||||
activity.getBottomSheet().prependItems(
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_set_student_number)
|
||||
.withIcon(SzkolnyFont.Icon.szf_clipboard_list_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
setNumberDialog();
|
||||
}),
|
||||
new BottomSheetSeparatorItem(true),
|
||||
new BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_mark_everything_as_read)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check_outline)
|
||||
.withOnClickListener(v3 -> {
|
||||
activity.getBottomSheet().close();
|
||||
AsyncTask.execute(() -> app.db.metadataDao().setAllSeen(App.profileId, true));
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
);
|
||||
activity.gainAttention();
|
||||
}
|
||||
|
||||
public void setNumberDialog() {
|
||||
new MaterialDialog.Builder(activity)
|
||||
.title(R.string.card_lucky_number_set_title)
|
||||
.content(R.string.card_lucky_number_set_text)
|
||||
.inputType(InputType.TYPE_CLASS_NUMBER)
|
||||
.input(null, app.profile.getStudentNumber() == -1 ? "" : Utils.intToStr(app.profile.getStudentNumber()), (dialog, input) -> {
|
||||
try {
|
||||
app.profile.setStudentNumber(Utils.strToInt(input.toString()));
|
||||
AsyncTask.execute(() -> app.profileSaveAsync());
|
||||
activity.reloadTarget();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Toast.makeText(activity, R.string.incorrect_format, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
public static String plural(Context c, @PluralsRes int resId, int value) {
|
||||
return c.getResources().getQuantityString(resId, value, value);
|
||||
}
|
||||
|
||||
public static long updateInterval(App app, Time diff) {
|
||||
//Log.d(TAG, "Millis is "+System.currentTimeMillis() % 1000+", update in "+(1000-(System.currentTimeMillis() % 1000)));
|
||||
if (app.config.getTimetable().getCountInSeconds()) {
|
||||
return 1000-(System.currentTimeMillis() % 1000);
|
||||
}
|
||||
if (diff.minute > 10) {
|
||||
//Log.d(TAG, "60 secs");
|
||||
return 60000-(System.currentTimeMillis() % 60000);
|
||||
}
|
||||
else if (diff.minute >= 1 && false) {
|
||||
//Log.d(TAG, "3 secs");
|
||||
return 3000-(System.currentTimeMillis() % 3000);
|
||||
}
|
||||
else if (diff.second >= 40 && false) {
|
||||
//Log.d(TAG, "2 secs");
|
||||
return 2000-(System.currentTimeMillis() % 2000);
|
||||
}
|
||||
else {
|
||||
Log.d(TAG, "1 sec");
|
||||
return 1000-(System.currentTimeMillis() % 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public static String timeTill(Context c, Time t1, Time t2) {
|
||||
return timeTill(c, Time.diff(t1, t2));
|
||||
}
|
||||
public static String timeTill(Context c, Time diff) {
|
||||
return timeTill(c, diff, false);
|
||||
}
|
||||
public static String timeTill(Context c, Time diff, boolean countInSeconds) {
|
||||
return timeTill(c, diff, countInSeconds, " ");
|
||||
}
|
||||
public static String timeTill(Context c, Time diff, boolean countInSeconds, String textDelimiter) {
|
||||
if (countInSeconds) {
|
||||
int seconds = diff.second + diff.minute * 60 + diff.hour * 3600;
|
||||
return plural(c, R.plurals.time_till_text, seconds)+textDelimiter+plural(c, R.plurals.time_till_seconds, seconds);
|
||||
}
|
||||
if (diff.hour < 1 && diff.minute < 1) {
|
||||
return plural(c, R.plurals.time_till_text, diff.second)+textDelimiter+plural(c, R.plurals.time_till_seconds, diff.second);
|
||||
}
|
||||
else if (diff.hour < 1 && diff.minute < 5) {
|
||||
return plural(c, R.plurals.time_till_text, diff.minute)+textDelimiter+plural(c, R.plurals.time_till_minutes, diff.minute)+" "+plural(c, R.plurals.time_till_seconds, diff.second);
|
||||
}
|
||||
else if (diff.hour < 1) {
|
||||
return plural(c, R.plurals.time_till_text, diff.minute)+textDelimiter+plural(c, R.plurals.time_till_minutes, diff.minute);
|
||||
}
|
||||
else { // diff.hour > 1
|
||||
return plural(c, R.plurals.time_till_text, diff.hour)+textDelimiter+plural(c, R.plurals.time_till_hours, diff.hour)+" "+plural(c, R.plurals.time_till_minutes, diff.minute);
|
||||
}
|
||||
}
|
||||
|
||||
public static String timeLeft(Context c, Time diff) {
|
||||
return timeLeft(c, diff, false);
|
||||
}
|
||||
public static String timeLeft(Context c, Time diff, boolean countInSeconds) {
|
||||
return timeLeft(c, diff, countInSeconds, " ");
|
||||
}
|
||||
public static String timeLeft(Context c, Time diff, boolean countInSeconds, String textDelimiter) {
|
||||
if (countInSeconds) {
|
||||
int seconds = diff.second + diff.minute * 60 + diff.hour * 3600;
|
||||
return plural(c, R.plurals.time_left_text, seconds)+textDelimiter+plural(c, R.plurals.time_left_seconds, seconds);
|
||||
}
|
||||
if (diff.hour < 1 && diff.minute < 1) {
|
||||
return plural(c, R.plurals.time_left_text, diff.second)+textDelimiter+plural(c, R.plurals.time_left_seconds, diff.second);
|
||||
}
|
||||
else if (diff.hour < 1 && diff.minute < 5) {
|
||||
return plural(c, R.plurals.time_left_text, diff.minute)+textDelimiter+plural(c, R.plurals.time_left_minutes, diff.minute)+" "+plural(c, R.plurals.time_left_seconds, diff.second);
|
||||
}
|
||||
else if (diff.hour < 1) {
|
||||
return plural(c, R.plurals.time_left_text, diff.minute)+textDelimiter+plural(c, R.plurals.time_left_minutes, diff.minute);
|
||||
}
|
||||
else { // diff.hour > 1
|
||||
return plural(c, R.plurals.time_left_text, diff.hour)+textDelimiter+plural(c, R.plurals.time_left_hours, diff.hour)+" "+plural(c, R.plurals.time_left_minutes, diff.minute);
|
||||
}
|
||||
}
|
||||
|
||||
public static void buttonAddDrawable(Context c, Button button, CommunityMaterial.Icon icon)
|
||||
{
|
||||
button.setCompoundDrawables(null, null, new IconicsDrawable(c)
|
||||
.icon(icon)
|
||||
.color(IconicsColor.colorInt(Utils.getAttr(c, android.R.attr.textColorPrimary)))
|
||||
.size(IconicsSize.dp(16)), null);
|
||||
}
|
||||
|
||||
|
||||
private void updateCardGrades(Context c, Activity a, View root, int maxWidthPx) {
|
||||
if (a == null || !isAdded())
|
||||
return;
|
||||
TextView cardGradesNoData = root.findViewById(R.id.cardGradesNoData);
|
||||
|
||||
app.db.gradeDao().getAllWhere(App.profileId, "gradeSemester = "+ app.profile.getCurrentSemester() +" AND addedDate > "+(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000)).observe(this, grades -> {
|
||||
List<ItemGradesSubjectModel> subjectList = new ArrayList<>();
|
||||
|
||||
// now we have all grades from the newest to the oldest
|
||||
for (GradeFull grade: grades) {
|
||||
ItemGradesSubjectModel model = ItemGradesSubjectModel.searchModelBySubjectId(subjectList, grade.subjectId);
|
||||
if (model == null) {
|
||||
subjectList.add(new ItemGradesSubjectModel(app.profile, new Subject(App.profileId, grade.subjectId, grade.subjectLongName, grade.subjectShortName), new ArrayList<>(), new ArrayList<>()));
|
||||
model = ItemGradesSubjectModel.searchModelBySubjectId(subjectList, grade.subjectId);
|
||||
}
|
||||
if (model != null) { // should always be not null
|
||||
model.grades1.add(grade);
|
||||
}
|
||||
}
|
||||
|
||||
float scale = c.getResources().getDisplayMetrics().density;
|
||||
int _5dp = (int) (5 * scale + 0.5f);
|
||||
int _8dp = (int) (8 * scale + 0.5f);
|
||||
|
||||
LinearLayout cardGradesList = root.findViewById(R.id.cardGradesList);
|
||||
cardGradesList.removeAllViews();
|
||||
|
||||
LinearLayout.LayoutParams textLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
textLayoutParams.setMargins(0, 0, _5dp, 0);
|
||||
|
||||
LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
linearLayoutParams.setMargins(_8dp, 0, _8dp, _5dp);
|
||||
|
||||
//Log.d(TAG, "maxWidthPx "+maxWidthPx);
|
||||
|
||||
int count = 0;
|
||||
|
||||
if (subjectList.size() > 0) {
|
||||
for (ItemGradesSubjectModel subjectModel : subjectList) {
|
||||
if (count++ >= 8) {
|
||||
//continue;
|
||||
}
|
||||
LinearLayout gradeItem = new LinearLayout(cardGradesList.getContext());
|
||||
gradeItem.setOrientation(LinearLayout.HORIZONTAL);
|
||||
|
||||
int totalWidthPx = 0;//subjectName.getMeasuredWidth() + _5dp;
|
||||
|
||||
|
||||
boolean ellipsized = false;
|
||||
|
||||
for (GradeFull grade : subjectModel.grades1) {
|
||||
if (ellipsized)
|
||||
continue;
|
||||
int gradeColor;
|
||||
if (App.getConfig().forProfile().getGrades().getColorMode() == Profile.COLOR_MODE_DEFAULT) {
|
||||
gradeColor = grade.color;
|
||||
}
|
||||
else {
|
||||
gradeColor = Colors.gradeToColor(grade);
|
||||
}
|
||||
|
||||
TextView gradeName = new TextView(gradeItem.getContext());
|
||||
gradeName.setText(grade.name);
|
||||
if (grade.type == TYPE_SEMESTER1_PROPOSED
|
||||
|| grade.type == TYPE_SEMESTER2_PROPOSED) {
|
||||
gradeName.setText(getString(R.string.grade_semester_proposed_format, grade.name));
|
||||
}
|
||||
else if (grade.type == TYPE_SEMESTER1_FINAL
|
||||
|| grade.type == TYPE_SEMESTER2_FINAL) {
|
||||
gradeName.setText(getString(R.string.grade_semester_final_format, grade.name));
|
||||
}
|
||||
else if (grade.type == TYPE_YEAR_PROPOSED) {
|
||||
gradeName.setText(getString(R.string.grade_year_proposed_format, grade.name));
|
||||
}
|
||||
else if (grade.type == TYPE_YEAR_FINAL) {
|
||||
gradeName.setText(getString(R.string.grade_year_final_format, grade.name));
|
||||
}
|
||||
gradeName.setTextColor(ColorUtils.calculateLuminance(gradeColor) > 0.25 ? 0xff000000 : 0xffffffff);
|
||||
gradeName.setTypeface(null, Typeface.BOLD);
|
||||
gradeName.setBackgroundResource(R.drawable.bg_rounded_4dp);
|
||||
gradeName.getBackground().setColorFilter(new PorterDuffColorFilter(gradeColor, PorterDuff.Mode.MULTIPLY));
|
||||
gradeName.setPadding(_5dp, 0, _5dp, 0);
|
||||
|
||||
gradeName.measure(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
totalWidthPx += gradeName.getMeasuredWidth() + _5dp;
|
||||
//Log.d(TAG, "totalWidthPx "+totalWidthPx);
|
||||
if (totalWidthPx >= (float)maxWidthPx / 1.5f) {
|
||||
ellipsized = true;
|
||||
TextView ellipsisText = new TextView(gradeItem.getContext());
|
||||
ellipsisText.setText(R.string.ellipsis);
|
||||
ellipsisText.setTextAppearance(gradeItem.getContext(), R.style.NavView_TextView);
|
||||
ellipsisText.setTypeface(null, Typeface.BOLD);
|
||||
ellipsisText.setPadding(0, 0, 0, 0);
|
||||
gradeItem.addView(ellipsisText, textLayoutParams);
|
||||
}
|
||||
else {
|
||||
gradeItem.addView(gradeName, textLayoutParams);
|
||||
}
|
||||
}
|
||||
|
||||
TextView subjectName = new TextView(gradeItem.getContext());
|
||||
Subject subject = subjectModel.subject;
|
||||
subjectName.setText(" z "+(subject != null ? subject.longName : ""));
|
||||
subjectName.setEllipsize(TextUtils.TruncateAt.END);
|
||||
subjectName.setSingleLine();
|
||||
subjectName.measure(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
//Log.d(TAG, "subjectName.width "+totalWidthPx);
|
||||
//subjectName.setMaxWidth(maxWidthPx - totalWidthPx);
|
||||
|
||||
gradeItem.addView(subjectName, textLayoutParams);
|
||||
|
||||
cardGradesList.addView(gradeItem, linearLayoutParams);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cardGradesNoData.setVisibility(View.VISIBLE);
|
||||
cardGradesList.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
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(MainActivity.DRAWER_ITEM_GRADES, null);
|
||||
}), 100)));
|
||||
|
||||
//new Handler().postDelayed(() -> a.runOnUiThread(() -> updateCardGrades(c, a, root)), newRefreshInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
//if (timetableCard != null)
|
||||
// timetableCard.destroy();
|
||||
}
|
||||
|
||||
private void configCardGrades(Context c, LayoutInflater layoutInflater, Activity a, ViewGroup insertPoint) {
|
||||
View root = layoutInflater.inflate(R.layout.card_grades, null);
|
||||
DisplayMetrics displayMetrics = c.getResources().getDisplayMetrics();
|
||||
updateCardGrades(c, a, root, displayMetrics.widthPixels - Utils.dpToPx((app.config.getUi().getMiniMenuVisible() ? 72 : 0)/*miniDrawer size*/ + 24 + 24/*left and right offsets*/ + 16/*ellipsize width*/));
|
||||
insertPoint.addView(root, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
}
|
@ -17,11 +17,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.ExtensionsKt;
|
||||
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.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 HomeFragmentOld.plural(context, R.plurals.time_till_days, Math.abs(dayDiff));
|
||||
return ExtensionsKt.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, HomeFragmentOld.plural(context, R.plurals.time_till_days, Math.abs(dayDiff)));
|
||||
return context.getString(R.string.ago_format, ExtensionsKt.plural(context, R.plurals.time_till_days, Math.abs(dayDiff)));
|
||||
}
|
||||
return context.getString(R.string.today);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.BuildConfig;
|
||||
import pl.szczodrzynski.edziennik.ExtensionsKt;
|
||||
import pl.szczodrzynski.edziennik.MainActivity;
|
||||
import pl.szczodrzynski.edziennik.Notifier;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
@ -52,7 +53,6 @@ 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.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,
|
||||
HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60)
|
||||
ExtensionsKt.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60)
|
||||
);
|
||||
return getString(
|
||||
R.string.settings_sync_sync_interval_subtext_format,
|
||||
HomeFragmentOld.plural(activity, R.plurals.time_till_hours, app.config.getSync().getInterval() / 60 / 60) +
|
||||
ExtensionsKt.plural(activity, R.plurals.time_till_hours, app.config.getSync().getInterval() / 60 / 60) +
|
||||
(app.config.getSync().getInterval() / 60 % 60 == 0 ?
|
||||
"" :
|
||||
" " + HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, app.config.getSync().getInterval() / 60 % 60)
|
||||
" " + ExtensionsKt.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(HomeFragmentOld.plural(activity, R.plurals.time_till_seconds, 30));
|
||||
intervalNames.add(HomeFragmentOld.plural(activity, R.plurals.time_till_minutes, 2));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_seconds, 30));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_minutes, 2));
|
||||
}
|
||||
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));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_minutes, 30));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_minutes, 45));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_hours, 1));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_hours, 1)+" "+ ExtensionsKt.plural(activity, R.plurals.time_till_minutes, 30));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_hours, 2));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_hours, 3));
|
||||
intervalNames.add(ExtensionsKt.plural(activity, R.plurals.time_till_hours, 4));
|
||||
List<Integer> intervals = new ArrayList<>();
|
||||
if (App.devMode && false) {
|
||||
intervals.add(30);
|
||||
|
@ -1,101 +0,0 @@
|
||||
<?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>
|
Loading…
x
Reference in New Issue
Block a user