Skip to content

Commit

Permalink
Merge branch 'app_new_design'
Browse files Browse the repository at this point in the history
  • Loading branch information
lubenard committed Dec 15, 2021
2 parents bf48b11 + 27982da commit 27cfdaa
Show file tree
Hide file tree
Showing 357 changed files with 8,152 additions and 1,527 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This app help you managing your contraceptive method (created for people using t
height="90">](https://play.google.com/store/apps/details?id=com.lubenard.oring_reminder)

## Screenshots
![unnamed](https://user-images.githubusercontent.com/42534397/133885035-61c36187-37cf-40b4-86bd-7ec0e7a6bd63.png)
![unnamed2](https://user-images.githubusercontent.com/42534397/133885037-007ff8d8-df34-42e4-a849-79fc7331e972.png)
![unnamed](https://user-images.githubusercontent.com/42534397/146053444-0a66ec5b-3076-4f63-9954-0d8253f80a26.png)
![unnamed2](https://user-images.githubusercontent.com/42534397/146053451-280ad090-6258-4fba-b78c-a1ef26368afa.png)
![unnamed3](https://user-images.githubusercontent.com/42534397/133885040-bb269ef1-4292-4f0d-9a16-8e2c82e7b777.png)

## Features:
Expand Down Expand Up @@ -44,11 +44,9 @@ For a debug version:
./gradlew assembleDebug
```


More informations here

## Tech part
This app is coded only in Java and support all the way to Android Kitkat (Api 19)
This app is coded only in Java and support all the way to Android Lollipop (Api 21)

Feel free to contribute or open a issue if needed.

## License
Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ plugins {
}

android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.lubenard.oring_reminder"
minSdkVersion 19
targetSdkVersion 30
versionCode 7
versionName "1.3"
minSdkVersion 21
targetSdkVersion 31
versionCode 10
versionName "2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -29,10 +29,10 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.oring"
android:configChanges="uiMode">
android:configChanges="uiMode"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -29,15 +30,17 @@
<receiver android:name=".broadcast_receivers.NotificationSenderBreaksBroadcastReceiver"/>
<receiver android:name=".broadcast_receivers.NotificationReceiverBroadcastReceiver"/>
<!--When boot is completed, launch this BroadcastReceiver with given Intents-->
<receiver android:name=".broadcast_receivers.AfterBootBroadcastReceiver">
<receiver android:name=".broadcast_receivers.AfterBootBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<!-- Widget manifest -->
<receiver android:name="CurrentSessionWidgetProvider" >
<receiver android:name="CurrentSessionWidgetProvider"
android:exported="false">
<intent-filter>
<!-- Used to manage the click on the button -->
<action android:name="com.lubenard.oring_reminder.WIDGET_BUTTON" />
Expand All @@ -47,6 +50,12 @@
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/current_sessions_widget_metadatas" />
</receiver>

<!-- Shortcut manifest -->
<receiver android:name=".ShortcutManager"
android:exported="false">
<intent-filter>
<action android:name="com.lubenard.oring_reminder.android.action.broadcast" />
</intent-filter>
</receiver>
</application>
</manifest>
81 changes: 42 additions & 39 deletions app/src/main/java/com/lubenard/oring_reminder/BackupRestore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
Expand All @@ -17,7 +16,7 @@
import androidx.preference.PreferenceManager;

import com.lubenard.oring_reminder.broadcast_receivers.AfterBootBroadcastReceiver;
import com.lubenard.oring_reminder.custom_components.RingModel;
import com.lubenard.oring_reminder.custom_components.RingSession;
import com.lubenard.oring_reminder.ui.EditEntryFragment;
import com.lubenard.oring_reminder.ui.SettingsFragment;
import com.lubenard.oring_reminder.utils.CsvWriter;
Expand Down Expand Up @@ -65,18 +64,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
* Launch the backup for export in CSV
*/
private void startBackupIntoCSV() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent dataToFileChooser = new Intent(Intent.ACTION_CREATE_DOCUMENT);
dataToFileChooser.setType("text/csv");
dataToFileChooser.putExtra(Intent.EXTRA_TITLE, "myDatasCSV.csv");
launchIntent(dataToFileChooser);
} else {
Log.w(TAG, "Your android version is pretty old. Save will be done at default location.");
Toast.makeText(this, R.string.toast_error_custom_path_backup_restore_android_too_old, Toast.LENGTH_LONG).show();
getDefaultFolder("csv");
createDefaultFileIfNeeded();
launchBackupRestore(exportPath);
}
Intent dataToFileChooser = new Intent(Intent.ACTION_CREATE_DOCUMENT);
dataToFileChooser.setType("text/csv");
dataToFileChooser.putExtra(Intent.EXTRA_TITLE, "myDatasCSV.csv");
launchIntent(dataToFileChooser);
}

/**
Expand All @@ -99,18 +90,10 @@ private void launchIntent(Intent dataToFileChooser) {
* Start export in XML
*/
private void startBackupIntoXML() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent dataToFileChooser = new Intent(Intent.ACTION_CREATE_DOCUMENT);
dataToFileChooser.setType("text/xml");
dataToFileChooser.putExtra(Intent.EXTRA_TITLE, "myDatas.xml");
launchIntent(dataToFileChooser);
} else {
Log.w(TAG, "Your android version is pretty old. Save will be done at default location.");
Toast.makeText(this, R.string.toast_error_custom_path_backup_restore_android_too_old, Toast.LENGTH_LONG).show();
getDefaultFolder("xml");
createDefaultFileIfNeeded();
launchBackupRestore(exportPath);
}
Intent dataToFileChooser = new Intent(Intent.ACTION_CREATE_DOCUMENT);
dataToFileChooser.setType("text/xml");
dataToFileChooser.putExtra(Intent.EXTRA_TITLE, "myDatas.xml");
launchIntent(dataToFileChooser);
}

/**
Expand Down Expand Up @@ -153,16 +136,9 @@ private void getDefaultFolder(String extension) {
*/
private void startRestoreFromXML() {
Log.d(TAG, "startRestoreFromXML");
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent dataToFileChooser = new Intent(Intent.ACTION_GET_CONTENT);
dataToFileChooser.setType("text/xml");
launchIntent(dataToFileChooser);
} else {
Log.w(TAG, "Android version too old. Restore will be from default location");
Toast.makeText(this, R.string.toast_error_custom_path_backup_restore_android_too_old, Toast.LENGTH_LONG).show();
getDefaultFolder("xml");
launchBackupRestore(exportPath);
}
Intent dataToFileChooser = new Intent(Intent.ACTION_GET_CONTENT);
dataToFileChooser.setType("text/xml");
launchIntent(dataToFileChooser);
}

/**
Expand Down Expand Up @@ -251,14 +227,14 @@ private void saveDatasIntoXml(XmlWriter xmlWriter) {
try {
xmlWriter.writeEntity("datas");
// Contain all entrys
ArrayList<RingModel> datas = dbManager.getAllDatasForAllEntrys();
ArrayList<RingSession> datas = dbManager.getAllDatasForAllEntrys();
for (int i = 0; i < datas.size(); i++) {
xmlWriter.writeEntity("session");
xmlWriter.writeAttribute("dateTimePut", datas.get(i).getDatePut());
xmlWriter.writeAttribute("dateTimeRemoved", datas.get(i).getDateRemoved());
xmlWriter.writeAttribute("isRunning", String.valueOf(datas.get(i).getIsRunning()));
xmlWriter.writeAttribute("timeWeared", String.valueOf(datas.get(i).getTimeWeared()));
ArrayList<RingModel> pauses = dbManager.getAllPausesForId(datas.get(i).getId(), true);
ArrayList<RingSession> pauses = dbManager.getAllPausesForId(datas.get(i).getId(), true);
if (pauses.size() > 0) {
Log.d(TAG, "Break exist for session " + datas.get(i).getId() + ". There is " + pauses.size() + " breaks");
for (int j = 0; j != pauses.size(); j++) {
Expand Down Expand Up @@ -410,6 +386,27 @@ private void restoreSettingsFromXml(InputStream inputStream) {
SettingsFragment.restartActivity();
}

private void checkAppVersion(InputStream inputStream) {
try {
XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance();
XmlPullParser myParser = xmlFactoryObject.newPullParser();

myParser.setInput(inputStream, null);

// Skip the first element
int eventType = myParser.next();
if (eventType == XmlPullParser.START_TAG && myParser.getName().equals("app_version")) {
myParser.next();
if (myParser.getText().equals(getString(R.string.app_version)))
Log.d(TAG, "Same app version !");
else
Log.d(TAG, "Not same app version ! " + myParser.getText() + "/" + getString(R.string.app_version));
}
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
}
}

/**
* Actually launch the backup system depending on what to do.
* This function is executed when we now everything is ready for export
Expand All @@ -427,6 +424,11 @@ private void launchBackupRestore(String filePath) {
try {
OutputStream outputStream = getContentResolver().openOutputStream(uri);
XmlWriter xmlWriter = new XmlWriter(outputStream);
// Write app version in xml export, for warning user if
// saves are imported from earlier version of the app
xmlWriter.writeEntity("app_version");
xmlWriter.writeText(getString(R.string.app_version));
xmlWriter.endEntity();
if (shouldBackupRestoreDatas)
saveDatasIntoXml(xmlWriter);
if (shouldBackupRestoreSettings)
Expand All @@ -441,6 +443,7 @@ private void launchBackupRestore(String filePath) {
Log.d(TAG, "ActivityResult restore from path: " + filePath);
try {
InputStream inputStream = getContentResolver().openInputStream(uri);
//checkAppVersion(inputStream);
if (shouldBackupRestoreDatas)
restoreDatasFromXml(inputStream);
// TODO: HOTFIX ! I should not need to reopen a stream (at least i think so)
Expand Down Expand Up @@ -486,7 +489,7 @@ private void saveDatasIntoCsv(CsvWriter csvWriter) {

ArrayList<String> formattedDatas = new ArrayList<>();
// Contain all entrys
ArrayList<RingModel> rawDatas = dbManager.getAllDatasForAllEntrys();
ArrayList<RingSession> rawDatas = dbManager.getAllDatasForAllEntrys();
for (int i = 0; i < rawDatas.size(); i++) {
String[] datePut = rawDatas.get(i).getDatePut().split(" ");
String[] dateRemoved = rawDatas.get(i).getDateRemoved().split(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;

import androidx.preference.PreferenceManager;

import com.lubenard.oring_reminder.broadcast_receivers.AfterBootBroadcastReceiver;
import com.lubenard.oring_reminder.broadcast_receivers.NotificationSenderBreaksBroadcastReceiver;
import com.lubenard.oring_reminder.custom_components.RingModel;
import com.lubenard.oring_reminder.custom_components.RingSession;
import com.lubenard.oring_reminder.ui.EditEntryFragment;
import com.lubenard.oring_reminder.ui.EntryDetailsFragment;
import com.lubenard.oring_reminder.utils.Utils;

import java.util.ArrayList;
Expand All @@ -42,6 +40,11 @@ public class CurrentSessionWidgetProvider extends AppWidgetProvider {
public static final String WIDGET_BUTTON_START_BREAK = "com.lubenard.oring_reminder.WIDGET_BUTTON_START_BREAK";
public static final String WIDGET_BUTTON_STOP_BREAK = "com.lubenard.oring_reminder.WIDGET_BUTTON_STOP_BREAK";

public static final String APPWIDGET_ENABLED = "android.appwidget.action.APPWIDGET_ENABLED";
public static final String APPWIDGET_UPDATE = "android.appwidget.action.APPWIDGET_UPDATE";
public static final String APPWIDGET_DELETED = "android.appwidget.action.APPWIDGET_DELETED";
public static final String APPWIDGET_UPDATE_OPTIONS = "android.appwidget.action.APPWIDGET_UPDATE_OPTIONS";

private static final String TAG = "Widget";

public static boolean isThereAWidget = false;
Expand All @@ -66,15 +69,15 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
if (dbManager == null)
dbManager = new DbManager(context);

RingModel lastEntry = dbManager.getLastRunningEntry();
RingSession lastEntry = dbManager.getLastRunningEntry();

// If entering this condition, this mean a session is currently active
if (lastEntry != null) {
Log.d(TAG, "A current session has been found");

Intent intent3 = new Intent(context, getClass());

ArrayList<RingModel> session_breaks = dbManager.getAllPausesForId(dbManager.getLastRunningEntry().getId(), true);
ArrayList<RingSession> session_breaks = dbManager.getAllPausesForId(dbManager.getLastRunningEntry().getId(), true);

if (session_breaks.size() > 0) {
if (session_breaks.get(0).getIsRunning() == 1) {
Expand Down Expand Up @@ -204,42 +207,51 @@ public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.d(TAG, "Widget receives OnRecieve command to update");
Log.d(TAG, "intent action is " + intent.getAction());
switch (intent.getAction()) {
// Clicked on the 'Start Session' button
case WIDGET_BUTTON_START:
EditEntryFragment.setUpdateMainList(false);
new EditEntryFragment(context).insertNewEntry(Utils.getdateFormatted(new Date()), false);
break;
// Clicked on the 'Stop Session' button
case WIDGET_BUTTON_STOP:
dbManager.endSession(dbManager.getLastRunningEntry().getId());
break;
// Clicked on the 'Start break' button
case WIDGET_BUTTON_START_BREAK:
dbManager.createNewPause(dbManager.getLastRunningEntry().getId(), Utils.getdateFormatted(new Date()), "NOT SET YET", 1);
// Cancel alarm until breaks are set as finished.
// Only then set a new alarm date
Log.d(TAG, "Cancelling alarm for entry: " + dbManager.getLastRunningEntry().getId());
EditEntryFragment.cancelAlarm(context, dbManager.getLastRunningEntry().getId());
setBreakAlarm(context, Utils.getdateFormatted(new Date()), dbManager.getLastRunningEntry().getId());
break;
// Clicked on the 'Stop break' button
case WIDGET_BUTTON_STOP_BREAK:
dbManager.endPause(dbManager.getLastRunningEntry().getId());
// Cancel the break notification if it is set as finished.
Intent intent4 = new Intent(context, NotificationSenderBreaksBroadcastReceiver.class).putExtra("action", 1);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent4, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
am.cancel(pendingIntent);
break;
default:
throw new IllegalStateException("Unexpected value: " + intent.getAction());
}

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
ComponentName thisAppWidget = new ComponentName(context.getPackageName(), CurrentSessionWidgetProvider.class.getName());
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

if (intent != null && intent.getAction() != null) {
switch (intent.getAction()) {
// Clicked on the 'Start Session' button
case WIDGET_BUTTON_START:
EditEntryFragment.setUpdateMainList(false);
new EditEntryFragment(context).insertNewEntry(Utils.getdateFormatted(new Date()), false);
break;
// Clicked on the 'Stop Session' button
case WIDGET_BUTTON_STOP:
dbManager.endSession(dbManager.getLastRunningEntry().getId());
break;
// Clicked on the 'Start break' button
case WIDGET_BUTTON_START_BREAK:
dbManager.createNewPause(dbManager.getLastRunningEntry().getId(), Utils.getdateFormatted(new Date()), "NOT SET YET", 1);
// Cancel alarm until breaks are set as finished.
// Only then set a new alarm date
Log.d(TAG, "Cancelling alarm for entry: " + dbManager.getLastRunningEntry().getId());
EditEntryFragment.cancelAlarm(context, dbManager.getLastRunningEntry().getId());
setBreakAlarm(context, Utils.getdateFormatted(new Date()), dbManager.getLastRunningEntry().getId());
break;
// Clicked on the 'Stop break' button
case WIDGET_BUTTON_STOP_BREAK:
dbManager.endPause(dbManager.getLastRunningEntry().getId());
// Cancel the break notification if it is set as finished.
Intent intent4 = new Intent(context, NotificationSenderBreaksBroadcastReceiver.class).putExtra("action", 1);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent4, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
am.cancel(pendingIntent);
break;
case APPWIDGET_ENABLED:
case APPWIDGET_UPDATE:
case APPWIDGET_DELETED:
case APPWIDGET_UPDATE_OPTIONS:
onUpdate(context, appWidgetManager, appWidgetIds);
break;
default:
throw new IllegalStateException("Unexpected value: " + intent.getAction());
}
}

onUpdate(context, appWidgetManager, appWidgetIds);
}
}
Loading

0 comments on commit 27cfdaa

Please sign in to comment.