Skip to content

Commit

Permalink
1. some code clean up and details changes
Browse files Browse the repository at this point in the history
2. working on alarm before class and auto silent
  • Loading branch information
ali77gh committed Nov 26, 2018
1 parent 49bc0ba commit ffc1bc5
Show file tree
Hide file tree
Showing 44 changed files with 380 additions and 199 deletions.
34 changes: 31 additions & 3 deletions README.md
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
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.STORAGE" />

<!--for make phone silent-->
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

<!-- Permission to start Alarm on device reboot -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<!--todo lock screen rotation-->

<application
Expand All @@ -17,7 +23,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
Expand Down Expand Up @@ -62,6 +67,8 @@
android:resource="@xml/show_next_class_widget_info"/>
</receiver>

<receiver android:name=".core.alarm.Alarm15MinRepeat" />

</application>

</manifest>
51 changes: 9 additions & 42 deletions app/src/main/java/com/github/ali77gh/unitools/TestActivity.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}


Expand Down
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();
}
}
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);
}
}
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);
}
}
}
Loading

0 comments on commit ffc1bc5

Please sign in to comment.