From ffc1bc5ca45c7bb5f7f410d57c15f7a43f172fb6 Mon Sep 17 00:00:00 2001 From: ali77gh Date: Mon, 26 Nov 2018 22:16:44 +0330 Subject: [PATCH] 1. some code clean up and details changes 2. working on alarm before class and auto silent --- README.md | 34 ++++++- app/src/main/AndroidManifest.xml | 9 +- .../github/ali77gh/unitools/TestActivity.java | 51 ++--------- .../ali77gh/unitools/core/ContextHolder.java | 8 +- .../ali77gh/unitools/core/Translator.java | 9 +- .../unitools/core/alarm/Alarm15MinRepeat.java | 91 +++++++++++++++++++ .../core/alarm/CloseToClassAlert.java | 56 ++++++++++++ .../ali77gh/unitools/core/alarm/Silent.java | 43 +++++++++ .../unitools/core/audio/SilentManager.java | 26 ++++++ .../core/{QrCode => qrCode}/QrCodeTools.java | 4 +- .../unitools/core/tools/DateTimeTools.java | 2 +- .../ali77gh/unitools/core/tools/Sort.java | 8 +- .../unitools/data/{Model => model}/Event.java | 2 +- .../data/{Model => model}/Friend.java | 2 +- .../unitools/data/{Model => model}/Time.java | 2 +- .../data/{Model => model}/UClass.java | 2 +- .../data/{Model => model}/UserInfo.java | 5 +- .../data/{Repo => repo}/EventRepo.java | 5 +- .../data/{Repo => repo}/FileRepo.java | 2 +- .../data/{Repo => repo}/FriendRepo.java | 5 +- .../data/{Repo => repo}/UserInfoRepo.java | 6 +- .../unitools/uI/activities/HomeActivity.java | 2 +- .../uI/activities/SplashActivity.java | 6 +- .../uI/activities/WelcomeActivity.java | 12 +-- .../unitools/uI/dialogs/AddClassDialog.java | 4 +- .../unitools/uI/dialogs/AddEventDialog.java | 4 +- .../unitools/uI/dialogs/AddFriendDialog.java | 4 +- .../unitools/uI/dialogs/ClassInfoDialog.java | 2 +- .../unitools/uI/dialogs/EventInfoDialog.java | 2 +- .../unitools/uI/dialogs/FriendInfoDialog.java | 4 +- .../uI/dialogs/SettingsAlarmConfigDialog.java | 10 +- .../uI/dialogs/SetupWeekCounterDialog.java | 4 +- .../uI/dialogs/ShareClassesDialog.java | 7 +- .../uI/fragments/SettingsFragment.java | 24 ++++- .../unitools/uI/fragments/WallFragment.java | 13 +-- .../unitools/widget/ShowNextClassWidget.java | 39 +------- app/src/main/res/layout/activity_test.xml | 15 ++- app/src/main/res/layout/fragment_settings.xml | 5 + app/src/main/res/layout/fragment_wall.xml | 30 ++---- app/src/main/res/layout/item_spinner.xml | 2 +- app/src/main/res/layout/layout_about_us.xml | 4 +- app/src/main/res/values-fa/strings.xml | 4 +- app/src/main/res/values/strings.xml | 2 +- .../ali77gh/unitools/ExampleUnitTest.java | 8 +- 44 files changed, 380 insertions(+), 199 deletions(-) create mode 100644 app/src/main/java/com/github/ali77gh/unitools/core/alarm/Alarm15MinRepeat.java create mode 100644 app/src/main/java/com/github/ali77gh/unitools/core/alarm/CloseToClassAlert.java create mode 100644 app/src/main/java/com/github/ali77gh/unitools/core/alarm/Silent.java create mode 100644 app/src/main/java/com/github/ali77gh/unitools/core/audio/SilentManager.java rename app/src/main/java/com/github/ali77gh/unitools/core/{QrCode => qrCode}/QrCodeTools.java (95%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Model => model}/Event.java (85%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Model => model}/Friend.java (77%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Model => model}/Time.java (94%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Model => model}/UClass.java (76%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Model => model}/UserInfo.java (79%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Repo => repo}/EventRepo.java (89%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Repo => repo}/FileRepo.java (95%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Repo => repo}/FriendRepo.java (89%) rename app/src/main/java/com/github/ali77gh/unitools/data/{Repo => repo}/UserInfoRepo.java (92%) diff --git a/README.md b/README.md index 7a5ca7f..3b21181 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,40 @@ # UniTools -Tools for university students +
+under heavy development :) +
-# Screen shots + این نرم افزار به صورت آزاد و کاملا رایگان در اختیار دانشجویان قرار گرفته تا کار های روزانه ی دانشجویان را راحت تر کند. این اپلیکیشن را به دوستان خود معرفی کنید و اگر انتقاد یا پیشنهاد یا در خواست قابلیت خاصی را دارید حتما با من در میان بگذارید. شما میتوانید با اپلود کردن جزوات خود و نظر دادن در مورد اساتید به دانشجویان دیگر کمک کنید. +
+# screen shots

-# LICENSE +# امکانات +
+مدیریت کلاس ها +
+مدیریت رویداد ها +
+سایلنت کردن گوشی وقتی که سر کلاس هستید به صورت اتوماتیک +
+اشتراک گزاری کلاس با دوستان پشتیبانی از qr code +
+ویجت برای دیدن کلاس بعدی +
+آلارم هنگامی که به کلاس بعدی نزدیک میشوید +
+قابلیت بک اپ گیری +
+ +# دانلود +[دانلود](https://github.com/ali77gh/UniTools/raw/master/TODO ) + +# لایسنس [MIT](https://github.com/ali77gh/UniTools/raw/master/LICENSE) + +# todo +doc finder +Storage \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d78bec2..6320b0a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,12 @@ + + + + + + - + + \ No newline at end of file diff --git a/app/src/main/java/com/github/ali77gh/unitools/TestActivity.java b/app/src/main/java/com/github/ali77gh/unitools/TestActivity.java index 14e8297..4142a37 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/TestActivity.java +++ b/app/src/main/java/com/github/ali77gh/unitools/TestActivity.java @@ -1,17 +1,10 @@ package com.github.ali77gh.unitools; -import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.widget.ImageView; -import android.widget.Toast; -import com.github.ali77gh.unitools.core.QrCode.QrCodeTools; -import com.github.ali77gh.unitools.core.audio.VoicePlayer; -import com.github.ali77gh.unitools.core.audio.VoiceRecorder; -import com.github.ali77gh.unitools.data.Model.Friend; -import com.google.zxing.integration.android.IntentIntegrator; -import com.google.zxing.integration.android.IntentResult; +import com.github.ali77gh.unitools.core.alarm.Alarm15MinRepeat; +import com.github.ali77gh.unitools.core.alarm.CloseToClassAlert; public class TestActivity extends AppCompatActivity { @@ -21,40 +14,14 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); -// VoiceRecorder voiceRecorder = new VoiceRecorder(this); -// VoicePlayer voicePlayer = new VoicePlayer(this); + Alarm15MinRepeat alarm = new Alarm15MinRepeat(); - //recorder test -// voiceRecorder.Record(); -// -// findViewById(android.R.id.content).postDelayed(() -> { -// voiceRecorder.stop(); -// voiceRecorder.SaveTempAs("uyuti"); -// voicePlayer.play("uyuti"); -// }, 10000); + findViewById(R.id.test_start).setOnClickListener(view -> { + alarm.start(this); + }); - - QrCodeTools.LaunchCameraFromActivity(this); - -// String friendJson = "{\"name\":\"ali\",\"classList\":[{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}},{\"id\":\"fsalkfvslmv\",\"where\":\"b110\",\"what\":\"شیمی\",\"dayOfWeek\":3,\"time\":{\"hour\":12,\"min\":30}}]}\n"; -// Friend friend = QrCodeTools.Parse(friendJson); -// ImageView imageView = findViewById(R.id.image_qr_test); -// imageView.setImageBitmap(QrCodeTools.Generate(friend)); - - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); - if (result != null) { - if (result.getContents() == null) { - Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); - } else { - Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show(); - - } - } else { - super.onActivityResult(requestCode, resultCode, data); - } + findViewById(R.id.test_stop).setOnClickListener(view -> { + alarm.stop(this); + }); } } diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/ContextHolder.java b/app/src/main/java/com/github/ali77gh/unitools/core/ContextHolder.java index b4108fe..e54f10b 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/core/ContextHolder.java +++ b/app/src/main/java/com/github/ali77gh/unitools/core/ContextHolder.java @@ -2,10 +2,10 @@ import android.content.Context; -import com.github.ali77gh.unitools.data.Repo.EventRepo; -import com.github.ali77gh.unitools.data.Repo.FileRepo; -import com.github.ali77gh.unitools.data.Repo.FriendRepo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.repo.EventRepo; +import com.github.ali77gh.unitools.data.repo.FileRepo; +import com.github.ali77gh.unitools.data.repo.FriendRepo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; /** * Created by ali77gh on 10/12/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/Translator.java b/app/src/main/java/com/github/ali77gh/unitools/core/Translator.java index 0708acd..7da8903 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/core/Translator.java +++ b/app/src/main/java/com/github/ali77gh/unitools/core/Translator.java @@ -4,10 +4,9 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.tools.DateTimeTools; -import com.github.ali77gh.unitools.data.Model.Event; -import com.github.ali77gh.unitools.data.Model.UClass; -import com.github.ali77gh.unitools.data.Model.UserInfo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.Event; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; /** * Created by ali77gh on 10/12/18. @@ -50,7 +49,7 @@ public static String getEventReadable(Event event) { week = event.WeekNumber + " " + context.getString(R.string.weeks_later); } - return week + day + " " + NumToString(event.time.hour) + ":" + NumToString(event.time.min) + " " + event.what; + return week + " " + day + " " + NumToString(event.time.hour) + ":" + NumToString(event.time.min) + " " + event.what; } diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Alarm15MinRepeat.java b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Alarm15MinRepeat.java new file mode 100644 index 0000000..ff25e3e --- /dev/null +++ b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Alarm15MinRepeat.java @@ -0,0 +1,91 @@ +package com.github.ali77gh.unitools.core.alarm; + +import android.app.AlarmManager; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.widget.Toast; + +import com.github.ali77gh.unitools.R; + +import java.util.Calendar; +import java.util.Date; +import java.util.Random; + +import static android.content.Context.ALARM_SERVICE; + +/** + * Created by ali77gh on 11/25/18. + */ + +public class Alarm15MinRepeat extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + +// //this part runs every 15 min +// CloseToClassAlert.on15Min(context); +// Silent.on15Min(context); + TestNotifi(context); // debug +// + } + + public void start(Context context) { + + stop(context); // if there is a alarm active + int min = new Date().getMinutes(); + if (min < 15) { + min = 16 - min; + } else if (min >= 15 && min < 30) { + min = 31 - min; + } else if (min >= 30 && min < 45) { + min = 46 - min; + } else { //45 -> 60 + min = 61 - min; + } + + setAlarm(context, min); + } + + public void stop(Context context) { + Intent intent = new Intent(context, Alarm15MinRepeat.class); + PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0); + AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); + alarmManager.cancel(sender); + } + + public void setAlarm(Context context, int min) { + AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + int interval = 1000 * 60 * 15; + + /* Set the alarm to start at 10:30 AM */ + + Intent alarmIntent = new Intent(context, Alarm15MinRepeat.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); + + /* Repeating on every 20 minutes interval */ + manager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + min * 60 * 1000, + interval, pendingIntent); + } + + public void TestNotifi(Context context) { + + Toast.makeText(context, "hi", Toast.LENGTH_SHORT).show(); + + NotificationManager NM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + Notification notify = new Notification.Builder + (context).setContentTitle("test").setSmallIcon(R.mipmap.ic_launcher). + setContentText(now()).build(); + + + notify.flags |= Notification.FLAG_AUTO_CANCEL; + NM.notify(new Random().nextInt(100), notify); + } + + private String now() { + return new Date().toString(); + } +} diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/alarm/CloseToClassAlert.java b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/CloseToClassAlert.java new file mode 100644 index 0000000..0eb2b98 --- /dev/null +++ b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/CloseToClassAlert.java @@ -0,0 +1,56 @@ +package com.github.ali77gh.unitools.core.alarm; + + +import android.app.Notification; +import android.app.NotificationManager; +import android.content.Context; +import android.media.RingtoneManager; + +import com.github.ali77gh.unitools.R; +import com.github.ali77gh.unitools.core.ContextHolder; +import com.github.ali77gh.unitools.core.tools.DateTimeTools; +import com.github.ali77gh.unitools.core.tools.Sort; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.model.UserInfo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; + +import java.util.List; + +/** + * Created by ali77gh on 11/25/18. + */ + +public class CloseToClassAlert { + + static void on15Min(Context context){ + ContextHolder.initStatics(context); + List classes = UserInfoRepo.getUserInfo().Classes; + Sort.SortClass(classes); + PushNotifi(context,classes.get(0)); + } + + private static void PushNotifi(Context context, UClass nextClass) { + + UserInfo ui = UserInfoRepo.getUserInfo(); + if (ui.NotificationMode == UserInfo.NOTIFICATION_NOTHING) return; + + int def = nextClass.time.getMins() - DateTimeTools.getCurrentTime().getMins(); + int defConfig = ui.ReminderInMins; + if (def > defConfig || def < 0) return; + + String title = context.getString(R.string.next_class_is_close); + String body = nextClass.what + " " + nextClass.time.hour + ":" + nextClass.time.min; + int icon = R.mipmap.ic_launcher; + + NotificationManager NM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + Notification notify = new Notification.Builder + (context).setContentTitle(title).setContentText(body). + setContentTitle(title).setSmallIcon(icon).build(); + + if (ui.NotificationMode == UserInfo.NOTIFICATION_WITH_SOUND) + notify.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + + notify.flags |= Notification.FLAG_AUTO_CANCEL; + NM.notify(0, notify); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Silent.java b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Silent.java new file mode 100644 index 0000000..187ff1c --- /dev/null +++ b/app/src/main/java/com/github/ali77gh/unitools/core/alarm/Silent.java @@ -0,0 +1,43 @@ +package com.github.ali77gh.unitools.core.alarm; + +import android.content.Context; + +import com.github.ali77gh.unitools.core.ContextHolder; +import com.github.ali77gh.unitools.core.audio.SilentManager; +import com.github.ali77gh.unitools.core.tools.DateTimeTools; +import com.github.ali77gh.unitools.core.tools.Sort; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.model.UserInfo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; + +import java.util.List; + +/** + * Created by ali77gh on 11/25/18. + */ + +public class Silent { + + private static int classCount = 120; // 2 hours + + static void on15Min(Context context){ + ContextHolder.initStatics(context); + List classes = UserInfoRepo.getUserInfo().Classes; + Sort.SortClass(classes); + silent(context,classes.get(0)); + } + + private static void silent(Context context, UClass nextClass) { + + UserInfo ui = UserInfoRepo.getUserInfo(); + if (!ui.AutoSilent) return; + + int def = nextClass.time.getMins() - DateTimeTools.getCurrentTime().getMins(); + int defConfig = classCount; // 2 hours + if (def > defConfig || def < 0) { // todo + SilentManager.Silent(context); + } else { + SilentManager.Normal(context); + } + } +} diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/audio/SilentManager.java b/app/src/main/java/com/github/ali77gh/unitools/core/audio/SilentManager.java new file mode 100644 index 0000000..4c8a1c2 --- /dev/null +++ b/app/src/main/java/com/github/ali77gh/unitools/core/audio/SilentManager.java @@ -0,0 +1,26 @@ +package com.github.ali77gh.unitools.core.audio; + +import android.content.Context; +import android.media.AudioManager; + +import static android.media.AudioManager.RINGER_MODE_NORMAL; +import static android.media.AudioManager.RINGER_MODE_SILENT; + +/** + * Created by ali77gh on 11/25/18. + */ + +public class SilentManager { + + public static void Silent(Context context) { + getAudioManager(context).setRingerMode(RINGER_MODE_SILENT); + } + + public static void Normal(Context context) { + getAudioManager(context).setRingerMode(RINGER_MODE_NORMAL); + } + + private static AudioManager getAudioManager(Context context){ + return (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + } +} diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/QrCode/QrCodeTools.java b/app/src/main/java/com/github/ali77gh/unitools/core/qrCode/QrCodeTools.java similarity index 95% rename from app/src/main/java/com/github/ali77gh/unitools/core/QrCode/QrCodeTools.java rename to app/src/main/java/com/github/ali77gh/unitools/core/qrCode/QrCodeTools.java index 9f65f7d..6a950f6 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/core/QrCode/QrCodeTools.java +++ b/app/src/main/java/com/github/ali77gh/unitools/core/qrCode/QrCodeTools.java @@ -1,11 +1,11 @@ -package com.github.ali77gh.unitools.core.QrCode; +package com.github.ali77gh.unitools.core.qrCode; import android.app.Activity; import android.graphics.Bitmap; import android.app.Fragment; import android.graphics.Color; -import com.github.ali77gh.unitools.data.Model.Friend; +import com.github.ali77gh.unitools.data.model.Friend; import com.google.gson.Gson; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/tools/DateTimeTools.java b/app/src/main/java/com/github/ali77gh/unitools/core/tools/DateTimeTools.java index 4a4d6b1..db7d21d 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/core/tools/DateTimeTools.java +++ b/app/src/main/java/com/github/ali77gh/unitools/core/tools/DateTimeTools.java @@ -1,6 +1,6 @@ package com.github.ali77gh.unitools.core.tools; -import com.github.ali77gh.unitools.data.Model.Time; +import com.github.ali77gh.unitools.data.model.Time; import java.util.Date; diff --git a/app/src/main/java/com/github/ali77gh/unitools/core/tools/Sort.java b/app/src/main/java/com/github/ali77gh/unitools/core/tools/Sort.java index b2d7bff..fe54426 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/core/tools/Sort.java +++ b/app/src/main/java/com/github/ali77gh/unitools/core/tools/Sort.java @@ -1,9 +1,9 @@ package com.github.ali77gh.unitools.core.tools; -import com.github.ali77gh.unitools.data.Model.Event; -import com.github.ali77gh.unitools.data.Model.Friend; -import com.github.ali77gh.unitools.data.Model.Time; -import com.github.ali77gh.unitools.data.Model.UClass; +import com.github.ali77gh.unitools.data.model.Event; +import com.github.ali77gh.unitools.data.model.Friend; +import com.github.ali77gh.unitools.data.model.Time; +import com.github.ali77gh.unitools.data.model.UClass; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Event.java b/app/src/main/java/com/github/ali77gh/unitools/data/model/Event.java similarity index 85% rename from app/src/main/java/com/github/ali77gh/unitools/data/Model/Event.java rename to app/src/main/java/com/github/ali77gh/unitools/data/model/Event.java index 8982bb1..b399090 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Event.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/model/Event.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Model; +package com.github.ali77gh.unitools.data.model; /** * Created by ali on 10/10/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Friend.java b/app/src/main/java/com/github/ali77gh/unitools/data/model/Friend.java similarity index 77% rename from app/src/main/java/com/github/ali77gh/unitools/data/Model/Friend.java rename to app/src/main/java/com/github/ali77gh/unitools/data/model/Friend.java index 2b2acb9..96550cf 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Friend.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/model/Friend.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Model; +package com.github.ali77gh.unitools.data.model; import java.util.List; diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Time.java b/app/src/main/java/com/github/ali77gh/unitools/data/model/Time.java similarity index 94% rename from app/src/main/java/com/github/ali77gh/unitools/data/Model/Time.java rename to app/src/main/java/com/github/ali77gh/unitools/data/model/Time.java index 2607bb0..48350f1 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Model/Time.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/model/Time.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Model; +package com.github.ali77gh.unitools.data.model; /** * Created by ali on 10/4/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Model/UClass.java b/app/src/main/java/com/github/ali77gh/unitools/data/model/UClass.java similarity index 76% rename from app/src/main/java/com/github/ali77gh/unitools/data/Model/UClass.java rename to app/src/main/java/com/github/ali77gh/unitools/data/model/UClass.java index 26cd825..f21fdd4 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Model/UClass.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/model/UClass.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Model; +package com.github.ali77gh.unitools.data.model; /** * Created by ali on 10/4/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Model/UserInfo.java b/app/src/main/java/com/github/ali77gh/unitools/data/model/UserInfo.java similarity index 79% rename from app/src/main/java/com/github/ali77gh/unitools/data/Model/UserInfo.java rename to app/src/main/java/com/github/ali77gh/unitools/data/model/UserInfo.java index 741e5c4..116c955 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Model/UserInfo.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/model/UserInfo.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Model; +package com.github.ali77gh.unitools.data.model; import java.util.List; @@ -13,7 +13,8 @@ public class UserInfo { public List Classes; public int NotificationMode; public int FirstDayOfUni; - public int reminderInMins; + public int ReminderInMins; + public boolean AutoSilent; public final static int NOTIFICATION_WITH_SOUND = 0; public final static int NOTIFICATION_JUST_NOTIFI = 1; diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/EventRepo.java b/app/src/main/java/com/github/ali77gh/unitools/data/repo/EventRepo.java similarity index 89% rename from app/src/main/java/com/github/ali77gh/unitools/data/Repo/EventRepo.java rename to app/src/main/java/com/github/ali77gh/unitools/data/repo/EventRepo.java index 8935baf..3c4eee7 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/EventRepo.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/repo/EventRepo.java @@ -1,14 +1,13 @@ -package com.github.ali77gh.unitools.data.Repo; +package com.github.ali77gh.unitools.data.repo; import android.content.Context; import com.example.easyrepolib.KeyValDb; import com.github.ali77gh.unitools.core.ShortIdGenerator; -import com.github.ali77gh.unitools.data.Model.Event; +import com.github.ali77gh.unitools.data.model.Event; import java.util.ArrayList; import java.util.List; -import java.util.UUID; /** * Created by ali on 10/10/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/FileRepo.java b/app/src/main/java/com/github/ali77gh/unitools/data/repo/FileRepo.java similarity index 95% rename from app/src/main/java/com/github/ali77gh/unitools/data/Repo/FileRepo.java rename to app/src/main/java/com/github/ali77gh/unitools/data/repo/FileRepo.java index 1a18d70..50d579d 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/FileRepo.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/repo/FileRepo.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Repo; +package com.github.ali77gh.unitools.data.repo; import android.content.Context; import android.graphics.Bitmap; diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/FriendRepo.java b/app/src/main/java/com/github/ali77gh/unitools/data/repo/FriendRepo.java similarity index 89% rename from app/src/main/java/com/github/ali77gh/unitools/data/Repo/FriendRepo.java rename to app/src/main/java/com/github/ali77gh/unitools/data/repo/FriendRepo.java index 07b217a..54a98e7 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/FriendRepo.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/repo/FriendRepo.java @@ -1,14 +1,13 @@ -package com.github.ali77gh.unitools.data.Repo; +package com.github.ali77gh.unitools.data.repo; import android.content.Context; import com.example.easyrepolib.KeyValDb; import com.github.ali77gh.unitools.core.ShortIdGenerator; -import com.github.ali77gh.unitools.data.Model.Friend; +import com.github.ali77gh.unitools.data.model.Friend; import java.util.ArrayList; import java.util.List; -import java.util.UUID; /** * Created by ali on 10/4/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/UserInfoRepo.java b/app/src/main/java/com/github/ali77gh/unitools/data/repo/UserInfoRepo.java similarity index 92% rename from app/src/main/java/com/github/ali77gh/unitools/data/Repo/UserInfoRepo.java rename to app/src/main/java/com/github/ali77gh/unitools/data/repo/UserInfoRepo.java index dde2ae0..67299e3 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/data/Repo/UserInfoRepo.java +++ b/app/src/main/java/com/github/ali77gh/unitools/data/repo/UserInfoRepo.java @@ -1,4 +1,4 @@ -package com.github.ali77gh.unitools.data.Repo; +package com.github.ali77gh.unitools.data.repo; import android.content.Context; @@ -6,8 +6,8 @@ import com.example.easyrepolib.repos.ObjectRepo; import com.github.ali77gh.unitools.core.ShortIdGenerator; import com.github.ali77gh.unitools.core.tools.DateTimeTools; -import com.github.ali77gh.unitools.data.Model.UClass; -import com.github.ali77gh.unitools.data.Model.UserInfo; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.model.UserInfo; import java.util.ArrayList; diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/HomeActivity.java b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/HomeActivity.java index b32b972..7f5e343 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/HomeActivity.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/HomeActivity.java @@ -12,7 +12,7 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.ContextHolder; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import com.github.ali77gh.unitools.uI.adapter.ViewPagerAdapter; import com.github.ali77gh.unitools.uI.fragments.Backable; import com.github.ali77gh.unitools.uI.fragments.StorageFragment; diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/SplashActivity.java b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/SplashActivity.java index d6064e8..149281a 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/SplashActivity.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/SplashActivity.java @@ -8,11 +8,7 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.ContextHolder; -import com.github.ali77gh.unitools.core.Translator; -import com.github.ali77gh.unitools.data.Repo.EventRepo; -import com.github.ali77gh.unitools.data.Repo.FileRepo; -import com.github.ali77gh.unitools.data.Repo.FriendRepo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import java.util.Locale; diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/WelcomeActivity.java b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/WelcomeActivity.java index 3c3967f..9ab3d3c 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/activities/WelcomeActivity.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/activities/WelcomeActivity.java @@ -7,11 +7,8 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.ContextHolder; -import com.github.ali77gh.unitools.data.Model.UserInfo; -import com.github.ali77gh.unitools.data.Repo.EventRepo; -import com.github.ali77gh.unitools.data.Repo.FileRepo; -import com.github.ali77gh.unitools.data.Repo.FriendRepo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.UserInfo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import java.util.ArrayList; @@ -35,13 +32,14 @@ protected void onCreate(Bundle savedInstanceState) { // init account new Thread(() -> { + //defaults UserInfo userInfo = new UserInfo(); - userInfo.LangId = getString(R.string.LangID); + userInfo.LangId = "fa"; userInfo.NotificationMode = UserInfo.NOTIFICATION_NOTHING; userInfo.DarkTheme = true; userInfo.Classes = new ArrayList<>(); userInfo.FirstDayOfUni = 0; - userInfo.reminderInMins = 50; + userInfo.ReminderInMins = 50; UserInfoRepo.setUserInfo(userInfo); }).start(); } diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddClassDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddClassDialog.java index e0f5705..1654893 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddClassDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddClassDialog.java @@ -11,8 +11,8 @@ import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.data.Model.Time; -import com.github.ali77gh.unitools.data.Model.UClass; +import com.github.ali77gh.unitools.data.model.Time; +import com.github.ali77gh.unitools.data.model.UClass; /** * Created by ali77gh on 10/12/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddEventDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddEventDialog.java index bf3babd..3867679 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddEventDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddEventDialog.java @@ -11,8 +11,8 @@ import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.data.Model.Event; -import com.github.ali77gh.unitools.data.Model.Time; +import com.github.ali77gh.unitools.data.model.Event; +import com.github.ali77gh.unitools.data.model.Time; /** * Created by ali77gh on 10/17/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddFriendDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddFriendDialog.java index 99dabee..18b6f84 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddFriendDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/AddFriendDialog.java @@ -16,8 +16,8 @@ import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.core.QrCode.QrCodeTools; -import com.github.ali77gh.unitools.data.Model.Friend; +import com.github.ali77gh.unitools.core.qrCode.QrCodeTools; +import com.github.ali77gh.unitools.data.model.Friend; import com.google.gson.Gson; import com.google.gson.JsonParseException; diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ClassInfoDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ClassInfoDialog.java index dbd9258..be81387 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ClassInfoDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ClassInfoDialog.java @@ -9,7 +9,7 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.Translator; -import com.github.ali77gh.unitools.data.Model.UClass; +import com.github.ali77gh.unitools.data.model.UClass; /** * Created by ali77gh on 11/14/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/EventInfoDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/EventInfoDialog.java index 01abe2b..5bf7237 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/EventInfoDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/EventInfoDialog.java @@ -9,7 +9,7 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.Translator; -import com.github.ali77gh.unitools.data.Model.Event; +import com.github.ali77gh.unitools.data.model.Event; /** * Created by ali77gh on 11/14/18. diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/FriendInfoDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/FriendInfoDialog.java index 41a3449..a901155 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/FriendInfoDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/FriendInfoDialog.java @@ -13,8 +13,8 @@ import com.github.ali77gh.unitools.core.ContextHolder; import com.github.ali77gh.unitools.core.Translator; import com.github.ali77gh.unitools.core.tools.Sort; -import com.github.ali77gh.unitools.data.Model.Friend; -import com.github.ali77gh.unitools.data.Model.UClass; +import com.github.ali77gh.unitools.data.model.Friend; +import com.github.ali77gh.unitools.data.model.UClass; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SettingsAlarmConfigDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SettingsAlarmConfigDialog.java index 0ed4f2f..aede016 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SettingsAlarmConfigDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SettingsAlarmConfigDialog.java @@ -13,8 +13,8 @@ import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.data.Model.UserInfo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.UserInfo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; /** * Created by ali77gh on 11/23/18. @@ -50,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) { return; } UserInfo ui = UserInfoRepo.getUserInfo(); - ui.reminderInMins = (Integer.valueOf(hour.getText().toString()) * 60) + Integer.valueOf(min.getText().toString()); + ui.ReminderInMins = (Integer.valueOf(hour.getText().toString()) * 60) + Integer.valueOf(min.getText().toString()); ui.NotificationMode = selectedNotifiType; UserInfoRepo.setUserInfo(ui); dismiss(); @@ -96,8 +96,8 @@ public void onNothingSelected(AdapterView adapterView) { }); UserInfo ui = UserInfoRepo.getUserInfo(); - hour.setText(String.valueOf ((int) ui.reminderInMins/60)); - min.setText(String.valueOf ( ui.reminderInMins%60)); + hour.setText(String.valueOf ((int) ui.ReminderInMins /60)); + min.setText(String.valueOf ( ui.ReminderInMins %60)); switch (ui.NotificationMode) { case UserInfo.NOTIFICATION_WITH_SOUND: notificationSpinner.setSelection(0); diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SetupWeekCounterDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SetupWeekCounterDialog.java index ad08008..549399c 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SetupWeekCounterDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/SetupWeekCounterDialog.java @@ -9,7 +9,7 @@ import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; /** * Created by ali77gh on 10/27/18. @@ -35,6 +35,8 @@ protected void onCreate(Bundle savedInstanceState) { cancel.setOnClickListener(view -> dismiss()); + input.setText(String.valueOf(UserInfoRepo.getWeekNumber()) ); + ok.setOnClickListener(view -> { if (!IsInt(input.getText().toString())) { Toast.makeText(mContext, "enter number :|", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ShareClassesDialog.java b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ShareClassesDialog.java index 9b54dcf..721b67a 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ShareClassesDialog.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/dialogs/ShareClassesDialog.java @@ -1,7 +1,6 @@ package com.github.ali77gh.unitools.uI.dialogs; import android.app.Dialog; -import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.graphics.Bitmap; @@ -11,9 +10,9 @@ import android.widget.ImageView; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.core.QrCode.QrCodeTools; -import com.github.ali77gh.unitools.data.Model.Friend; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.core.qrCode.QrCodeTools; +import com.github.ali77gh.unitools.data.model.Friend; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import com.google.gson.Gson; /** diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/SettingsFragment.java b/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/SettingsFragment.java index 756858a..a1940a3 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/SettingsFragment.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/SettingsFragment.java @@ -12,14 +12,15 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Spinner; +import android.widget.Switch; import android.widget.TextView; +import android.widget.Toast; import com.github.ali77gh.unitools.R; -import com.github.ali77gh.unitools.data.Model.UserInfo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.UserInfo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import com.github.ali77gh.unitools.uI.dialogs.SettingsAlarmConfigDialog; import java.util.Locale; @@ -32,6 +33,8 @@ public class SettingsFragment extends Fragment implements Backable { private Spinner languageSpinner; private LinearLayout aboutUsBtn; + private LinearLayout autoSilentBtn; + private Switch autoSilentSwitch; private FrameLayout aboutUs; public SettingsFragment() { @@ -44,17 +47,28 @@ public void onCreate(Bundle savedInstanceState) { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { View cView = inflater.inflate(R.layout.fragment_settings, container, false); languageSpinner = cView.findViewById(R.id.spinner_settings_language); + autoSilentBtn = cView.findViewById(R.id.linear_settings_auto_silent); + autoSilentSwitch = (Switch) autoSilentBtn.getChildAt(3); aboutUsBtn = cView.findViewById(R.id.linear_settings_about_us); aboutUs = cView.findViewById(R.id.layout_settings_about); LinearLayout reminder = cView.findViewById(R.id.linear_settings_reminder); reminder.setOnClickListener(view -> new SettingsAlarmConfigDialog(getActivity()).show()); + autoSilentBtn.setOnClickListener(view -> autoSilentSwitch.toggle()); + autoSilentSwitch.setOnCheckedChangeListener((compoundButton, b) -> { + UserInfo ui = UserInfoRepo.getUserInfo(); + ui.AutoSilent = b; + UserInfoRepo.setUserInfo(ui); + }); + + SetupLanguage(); LoadCurrentSettings(); SetupAboutUs(); @@ -75,6 +89,8 @@ private void LoadCurrentSettings() { default: throw new IllegalArgumentException("invalid language: " + ui.LangId); } + + autoSilentSwitch.setChecked(ui.AutoSilent); } private void SetupLanguage() { diff --git a/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/WallFragment.java b/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/WallFragment.java index 8a96339..1f31995 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/WallFragment.java +++ b/app/src/main/java/com/github/ali77gh/unitools/uI/fragments/WallFragment.java @@ -15,12 +15,12 @@ import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.Translator; import com.github.ali77gh.unitools.core.tools.Sort; -import com.github.ali77gh.unitools.data.Model.Event; -import com.github.ali77gh.unitools.data.Model.Friend; -import com.github.ali77gh.unitools.data.Model.UClass; -import com.github.ali77gh.unitools.data.Repo.EventRepo; -import com.github.ali77gh.unitools.data.Repo.FriendRepo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.Event; +import com.github.ali77gh.unitools.data.model.Friend; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.repo.EventRepo; +import com.github.ali77gh.unitools.data.repo.FriendRepo; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import com.github.ali77gh.unitools.uI.animation.ExpandAndCollapse; import com.github.ali77gh.unitools.uI.dialogs.AddClassDialog; import com.github.ali77gh.unitools.uI.dialogs.AddEventDialog; @@ -158,6 +158,7 @@ private void SetupListsAndFirstRow() { eventsFirstRow.setText(getString(R.string.you_have_no_event_yet)); List eventsString = new ArrayList<>(); List events = EventRepo.getAll(); + Sort.SortEvent(events); for (Event event : events) { if (events.indexOf(event) == 0) eventsFirstRow.setText(getResources().getString(R.string.next) + " " + Translator.getEventReadable(event)); diff --git a/app/src/main/java/com/github/ali77gh/unitools/widget/ShowNextClassWidget.java b/app/src/main/java/com/github/ali77gh/unitools/widget/ShowNextClassWidget.java index 27ccbc8..c6cbdbe 100644 --- a/app/src/main/java/com/github/ali77gh/unitools/widget/ShowNextClassWidget.java +++ b/app/src/main/java/com/github/ali77gh/unitools/widget/ShowNextClassWidget.java @@ -1,29 +1,20 @@ package com.github.ali77gh.unitools.widget; -import android.app.Notification; -import android.app.NotificationManager; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.media.RingtoneManager; -import android.net.Uri; import android.util.DisplayMetrics; -import android.util.Log; import android.widget.RemoteViews; -import android.widget.Toast; import com.github.ali77gh.unitools.R; import com.github.ali77gh.unitools.core.ContextHolder; import com.github.ali77gh.unitools.core.Translator; -import com.github.ali77gh.unitools.core.tools.DateTimeTools; import com.github.ali77gh.unitools.core.tools.Sort; -import com.github.ali77gh.unitools.data.Model.Time; -import com.github.ali77gh.unitools.data.Model.UClass; -import com.github.ali77gh.unitools.data.Model.UserInfo; -import com.github.ali77gh.unitools.data.Repo.UserInfoRepo; +import com.github.ali77gh.unitools.data.model.UClass; +import com.github.ali77gh.unitools.data.repo.UserInfoRepo; import com.github.ali77gh.unitools.uI.activities.SplashActivity; import java.util.List; @@ -49,7 +40,6 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a List classes = UserInfoRepo.getUserInfo().Classes; Sort.SortClass(classes); - PushNotifi(context, classes.get(0)); String number = context.getString(R.string.next_class) + " : " + Translator.getUClassReadable(classes.get(0)); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_show_next_class); @@ -80,29 +70,4 @@ private void SetupLang(Context context) { res.updateConfiguration(conf, dm); } - - private void PushNotifi(Context context, UClass nextClass) { - - UserInfo ui = UserInfoRepo.getUserInfo(); - if (ui.NotificationMode == UserInfo.NOTIFICATION_NOTHING) return; - - int def = nextClass.time.getMins() - DateTimeTools.getCurrentTime().getMins(); - int defConfig = ui.reminderInMins; - if (def > defConfig || def < 0) return; - - String title = context.getString(R.string.next_class_is_close); - String body = nextClass.what + " " + nextClass.time.hour + ":" + nextClass.time.min; - int icon = R.mipmap.ic_launcher; - - NotificationManager NM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - Notification notify = new Notification.Builder - (context).setContentTitle(title).setContentText(body). - setContentTitle(title).setSmallIcon(icon).build(); - - if (ui.NotificationMode == UserInfo.NOTIFICATION_WITH_SOUND) - notify.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - - notify.flags |= Notification.FLAG_AUTO_CANCEL; - NM.notify(0, notify); - } } diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml index f185259..fcde10f 100644 --- a/app/src/main/res/layout/activity_test.xml +++ b/app/src/main/res/layout/activity_test.xml @@ -6,9 +6,16 @@ android:layout_height="match_parent" tools:context="com.github.ali77gh.unitools.TestActivity"> - +