-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. some code clean up and details changes
2. working on alarm before class and auto silent
- Loading branch information
Showing
44 changed files
with
380 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
# UniTools | ||
Tools for university students | ||
<br> | ||
under heavy development :) | ||
<br> | ||
|
||
# Screen shots | ||
این نرم افزار به صورت آزاد و کاملا رایگان در اختیار دانشجویان قرار گرفته تا کار های روزانه ی دانشجویان را راحت تر کند. این اپلیکیشن را به دوستان خود معرفی کنید و اگر انتقاد یا پیشنهاد یا در خواست قابلیت خاصی را دارید حتما با من در میان بگذارید. شما میتوانید با اپلود کردن جزوات خود و نظر دادن در مورد اساتید به دانشجویان دیگر کمک کنید. | ||
<br> | ||
# screen shots | ||
<p float="left"> | ||
<img src= "https://github.com/ali77gh/UniTools/raw/master/ScreenShots/friend.png" height=500 /> | ||
<img src= "https://github.com/ali77gh/UniTools/raw/master/ScreenShots/share_classes.png" height=500 /> | ||
<img src= "https://github.com/ali77gh/UniTools/raw/master/ScreenShots/home_screen_shot.png" height=500 /> | ||
</p> | ||
|
||
# LICENSE | ||
# امکانات | ||
<br> | ||
مدیریت کلاس ها | ||
<br> | ||
مدیریت رویداد ها | ||
<br> | ||
سایلنت کردن گوشی وقتی که سر کلاس هستید به صورت اتوماتیک | ||
<br> | ||
اشتراک گزاری کلاس با دوستان پشتیبانی از qr code | ||
<br> | ||
ویجت برای دیدن کلاس بعدی | ||
<br> | ||
آلارم هنگامی که به کلاس بعدی نزدیک میشوید | ||
<br> | ||
قابلیت بک اپ گیری | ||
<br> | ||
|
||
# دانلود | ||
[دانلود](https://github.com/ali77gh/UniTools/raw/master/TODO ) | ||
|
||
# لایسنس | ||
[MIT](https://github.com/ali77gh/UniTools/raw/master/LICENSE) | ||
|
||
# todo | ||
doc finder | ||
Storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/github/ali77gh/unitools/core/alarm/Alarm15MinRepeat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/github/ali77gh/unitools/core/alarm/CloseToClassAlert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UClass> 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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/github/ali77gh/unitools/core/alarm/Silent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UClass> 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); | ||
} | ||
} | ||
} |
Oops, something went wrong.