fixed some of the widget bugs and removed assets

This commit is contained in:
Kima 2023-08-25 23:20:44 +02:00
parent bad9ed000b
commit 360426d851
18 changed files with 1142 additions and 1084 deletions

View File

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools" package="hu.refilc.naplo"> xmlns:tools="http://schemas.android.com/tools" package="hu.refilc.naplo">
<application android:name="${applicationName}" android:label="reFilc" tools:replace="android:label" android:icon="@mipmap/ic_launcher" <application android:name="${applicationName}" android:label="reFilc" tools:replace="android:label" android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"> android:requestLegacyExternalStorage="true">
<activity android:exported="true" android:name=".MainActivity" <activity android:exported="true" android:name="hu.refilc.naplo.MainActivity"
android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:launchMode="singleTop" android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"
@ -20,16 +20,26 @@
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with https://api.filcnaplo.hu --> <!-- Accepts URIs that begin with https://api.refilcapp.hu -->
<data <data
android:scheme="https" android:scheme="https"
android:host="api.filcnaplo.hu" android:host="api.refilcapp.hu"
android:pathPrefix="/callback" /> android:pathPrefix="/v1/auth/callback" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with https://refilc.hu -->
<data
android:scheme="https"
android:host="refilc.hu"
android:pathPrefix="/app" />
</intent-filter> </intent-filter>
</activity> </activity>
<meta-data android:name="flutterEmbedding" android:value="2" /> <meta-data android:name="flutterEmbedding" android:value="2" />
<receiver android:name=".widget_timetable.WidgetTimetable" <receiver android:name="hu.refilc.naplo.widget_timetable.WidgetTimetable"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@ -45,7 +55,7 @@
android:resource="@xml/home_widget_test_info" /> android:resource="@xml/home_widget_test_info" />
</receiver> </receiver>
<service android:name=".widget_timetable.WidgetTimetableService" <service android:name="hu.refilc.naplo.widget_timetable.WidgetTimetableService"
android:permission="android.permission.BIND_REMOTEVIEWS" /> android:permission="android.permission.BIND_REMOTEVIEWS" />
<receiver android:name="es.antonborri.home_widget.HomeWidgetBackgroundReceiver" <receiver android:name="es.antonborri.home_widget.HomeWidgetBackgroundReceiver"

View File

@ -1 +0,0 @@
../../../../../../../../../filcnaplo_premium/android/database

View File

@ -1,119 +1,119 @@
package hu.refilc.naplo.database; package hu.refilc.naplo.database;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import java.sql.SQLException; import java.sql.SQLException;
import hu.refilc.naplo.database.SQLiteHelper; import hu.refilc.naplo.database.SQLiteHelper;
public class DBManager { public class DBManager {
private Context context; private Context context;
private SQLiteDatabase database; private SQLiteDatabase database;
private SQLiteHelper dbHelper; private SQLiteHelper dbHelper;
public DBManager(Context c) { public DBManager(Context c) {
this.context = c; this.context = c;
} }
public DBManager open() throws SQLException { public DBManager open() throws SQLException {
this.dbHelper = new SQLiteHelper(this.context); this.dbHelper = new SQLiteHelper(this.context);
this.database = this.dbHelper.getWritableDatabase(); this.database = this.dbHelper.getWritableDatabase();
return this; return this;
} }
public void close() { public void close() {
this.dbHelper.close(); this.dbHelper.close();
} }
public Cursor fetchWidget(int wid) { public Cursor fetchWidget(int wid) {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_WIDGETS, new String[]{SQLiteHelper._ID, SQLiteHelper.DAY_SEL}, SQLiteHelper._ID + " = " + wid, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_WIDGETS, new String[]{SQLiteHelper._ID, SQLiteHelper.DAY_SEL}, SQLiteHelper._ID + " = " + wid, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchTimetable() { public Cursor fetchTimetable() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER_DATA, new String[]{SQLiteHelper.TIMETABLE}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER_DATA, new String[]{SQLiteHelper.TIMETABLE}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchLastUser() { public Cursor fetchLastUser() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LAST_ACCOUNT_ID}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LAST_ACCOUNT_ID}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchTheme() { public Cursor fetchTheme() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.THEME, SQLiteHelper.ACCENT_COLOR}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.THEME, SQLiteHelper.ACCENT_COLOR}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchPremiumToken() { public Cursor fetchPremiumToken() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_TOKEN}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_TOKEN}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchPremiumScopes() { public Cursor fetchPremiumScopes() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_SCOPES}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_SCOPES}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public Cursor fetchLocale() { public Cursor fetchLocale() {
Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LOCALE}, null, null, null, null, null); Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LOCALE}, null, null, null, null, null);
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
} }
return cursor; return cursor;
} }
public void deleteWidget(int _id) { public void deleteWidget(int _id) {
this.database.delete(SQLiteHelper.TABLE_NAME_WIDGETS, "_id=" + _id, null); this.database.delete(SQLiteHelper.TABLE_NAME_WIDGETS, "_id=" + _id, null);
} }
/*public void changeSettings(int _id, Map<String, String> map) { /*public void changeSettings(int _id, Map<String, String> map) {
ContentValues con = new ContentValues(); ContentValues con = new ContentValues();
for(Map.Entry<String, String> e: map.entrySet()){ for(Map.Entry<String, String> e: map.entrySet()){
con.put(e.getKey(), e.getValue()); con.put(e.getKey(), e.getValue());
} }
this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, "_id = " + _id, null); this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, "_id = " + _id, null);
} }
public void insertSettings(int _id, Map<String, String> map) { public void insertSettings(int _id, Map<String, String> map) {
ContentValues con = new ContentValues(); ContentValues con = new ContentValues();
for(Map.Entry<String, String> e: map.entrySet()){ for(Map.Entry<String, String> e: map.entrySet()){
con.put(e.getKey(), e.getValue()); con.put(e.getKey(), e.getValue());
//Log.d("Settings added", e.getKey() + " - " + e.getValue()); //Log.d("Settings added", e.getKey() + " - " + e.getValue());
} }
this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con);
}*/ }*/
public void insertSelDay(int _id, int day_sel) { public void insertSelDay(int _id, int day_sel) {
ContentValues con = new ContentValues(); ContentValues con = new ContentValues();
con.put(SQLiteHelper._ID, _id); con.put(SQLiteHelper._ID, _id);
con.put(SQLiteHelper.DAY_SEL, day_sel); con.put(SQLiteHelper.DAY_SEL, day_sel);
this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con);
} }
public int update(int _id, int day_sel) { public int update(int _id, int day_sel) {
ContentValues con = new ContentValues(); ContentValues con = new ContentValues();
con.put(SQLiteHelper.DAY_SEL, day_sel); con.put(SQLiteHelper.DAY_SEL, day_sel);
return this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, SQLiteHelper._ID + " = " + _id, null); return this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, SQLiteHelper._ID + " = " + _id, null);
} }
} }

View File

@ -1,36 +1,36 @@
package hu.refilc.naplo.database; package hu.refilc.naplo.database;
import android.content.Context; import android.content.Context;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
public class SQLiteHelper extends SQLiteOpenHelper { public class SQLiteHelper extends SQLiteOpenHelper {
private static final String CREATE_TABLE_WIDGET = " create table widgets ( _id INTEGER NOT NULL, day_sel INTEGER NOT NULL);"; private static final String CREATE_TABLE_WIDGET = " create table widgets ( _id INTEGER NOT NULL, day_sel INTEGER NOT NULL);";
private static final String DB_NAME = "app.db"; private static final String DB_NAME = "app.db";
private static final int DB_VERSION = 1; private static final int DB_VERSION = 1;
public static final String _ID = "_id"; public static final String _ID = "_id";
public static final String DAY_SEL = "day_sel"; public static final String DAY_SEL = "day_sel";
public static final String TIMETABLE = "timetable"; public static final String TIMETABLE = "timetable";
public static final String LAST_ACCOUNT_ID = "last_account_id"; public static final String LAST_ACCOUNT_ID = "last_account_id";
public static final String THEME = "theme"; public static final String THEME = "theme";
public static final String PREMIUM_TOKEN = "premium_token"; public static final String PREMIUM_TOKEN = "premium_token";
public static final String PREMIUM_SCOPES = "premium_scopes"; public static final String PREMIUM_SCOPES = "premium_scopes";
public static final String LOCALE = "language"; public static final String LOCALE = "language";
public static final String ACCENT_COLOR = "accent_color"; public static final String ACCENT_COLOR = "accent_color";
public static final String TABLE_NAME_WIDGETS = "widgets"; public static final String TABLE_NAME_WIDGETS = "widgets";
public static final String TABLE_NAME_USER_DATA = "user_data"; public static final String TABLE_NAME_USER_DATA = "user_data";
public static final String TABLE_NAME_SETTINGS = "settings"; public static final String TABLE_NAME_SETTINGS = "settings";
public SQLiteHelper(Context context) { public SQLiteHelper(Context context) {
super(context, DB_NAME, null, 7); super(context, DB_NAME, null, 7);
} }
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_WIDGET); db.execSQL(CREATE_TABLE_WIDGET);
} }
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS widgets"); db.execSQL("DROP TABLE IF EXISTS widgets");
onCreate(db); onCreate(db);
} }
} }

View File

@ -1 +0,0 @@
../../../../../../../../../filcnaplo_premium/android/utils

View File

@ -1,36 +1,36 @@
package hu.refilc.naplo.utils; package hu.refilc.naplo.utils;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
public class Utils { public class Utils {
public static boolean hasNetwork(Context context) { public static boolean hasNetwork(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo(); NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) { if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true; return true;
} }
return false; return false;
} }
public static Date getWeekStartDate() { public static Date getWeekStartDate() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
calendar.add(Calendar.DATE, -1); calendar.add(Calendar.DATE, -1);
} }
return calendar.getTime(); return calendar.getTime();
} }
public static Date getWeekEndDate() { public static Date getWeekEndDate() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
calendar.add(Calendar.DATE, 1); calendar.add(Calendar.DATE, 1);
} }
calendar.add(Calendar.DATE, -1); calendar.add(Calendar.DATE, -1);
return calendar.getTime(); return calendar.getTime();
} }
} }

View File

@ -1,65 +1,65 @@
package hu.refilc.naplo.utils; package hu.refilc.naplo.utils;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
public class Week { public class Week {
private final LocalDate start; private final LocalDate start;
private final LocalDate end; private final LocalDate end;
private Week(LocalDate start, LocalDate end) { private Week(LocalDate start, LocalDate end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
} }
public static Week current() { public static Week current() {
return fromDate(LocalDate.now()); return fromDate(LocalDate.now());
} }
public static Week fromId(int id) { public static Week fromId(int id) {
LocalDate _now = getYearStart().plusDays(id * 7L); LocalDate _now = getYearStart().plusDays(id * 7L);
return new Week(_now.minusDays(_now.getDayOfWeek().getValue() - 1), _now.plusDays(7 - _now.getDayOfWeek().getValue())); return new Week(_now.minusDays(_now.getDayOfWeek().getValue() - 1), _now.plusDays(7 - _now.getDayOfWeek().getValue()));
} }
public static Week fromDate(LocalDate date) { public static Week fromDate(LocalDate date) {
return new Week(date.minusDays(date.getDayOfWeek().getValue() - 1), date.plusDays(7 - date.getDayOfWeek().getValue())); return new Week(date.minusDays(date.getDayOfWeek().getValue() - 1), date.plusDays(7 - date.getDayOfWeek().getValue()));
} }
public Week next() { public Week next() {
return Week.fromDate(start.plusDays(8)); return Week.fromDate(start.plusDays(8));
} }
public int id() { public int id() {
return (int) Math.ceil(Duration.between(getYearStart().atStartOfDay(), start.atStartOfDay()).toDays() / 7f); return (int) Math.ceil(Duration.between(getYearStart().atStartOfDay(), start.atStartOfDay()).toDays() / 7f);
} }
private static LocalDate getYearStart() { private static LocalDate getYearStart() {
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
LocalDate start = getYearStart(now.getYear()); LocalDate start = getYearStart(now.getYear());
return start.isBefore(now) ? start : getYearStart(now.getYear() -1); return start.isBefore(now) ? start : getYearStart(now.getYear() -1);
} }
private static LocalDate getYearStart(int year) { private static LocalDate getYearStart(int year) {
LocalDate time = LocalDate.of(year, 9, 1); LocalDate time = LocalDate.of(year, 9, 1);
if (time.getDayOfWeek() == DayOfWeek.SATURDAY) if (time.getDayOfWeek() == DayOfWeek.SATURDAY)
return time.plusDays(2); return time.plusDays(2);
else if (time.getDayOfWeek() == DayOfWeek.SUNDAY) else if (time.getDayOfWeek() == DayOfWeek.SUNDAY)
return time.plusDays(1); return time.plusDays(1);
return time; return time;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Week week = (Week) o; Week week = (Week) o;
return this.id() == week.id(); return this.id() == week.id();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return id(); return id();
} }
} }

View File

@ -1 +0,0 @@
../../../../../../../../../filcnaplo_premium/android/widget_timetable

View File

@ -1,397 +1,397 @@
package hu.refilc.naplo.widget_timetable; package hu.refilc.naplo.widget_timetable;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider; import android.appwidget.AppWidgetProvider;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.Toast; import android.widget.Toast;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.format.TextStyle; import java.time.format.TextStyle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import hu.refilc.naplo.database.DBManager; import hu.refilc.naplo.database.DBManager;
import hu.refilc.naplo.MainActivity; import hu.refilc.naplo.MainActivity;
import hu.refilc.naplo.R; import hu.refilc.naplo.R;
import hu.refilc.naplo.utils.Week; import hu.refilc.naplo.utils.Week;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import es.antonborri.home_widget.HomeWidgetBackgroundIntent; import es.antonborri.home_widget.HomeWidgetBackgroundIntent;
import es.antonborri.home_widget.HomeWidgetLaunchIntent; import es.antonborri.home_widget.HomeWidgetLaunchIntent;
import es.antonborri.home_widget.HomeWidgetProvider; import es.antonborri.home_widget.HomeWidgetProvider;
public class WidgetTimetable extends HomeWidgetProvider { public class WidgetTimetable extends HomeWidgetProvider {
private static final String ACTION_WIDGET_CLICK_NAV_LEFT = "list_widget.ACTION_WIDGET_CLICK_NAV_LEFT"; private static final String ACTION_WIDGET_CLICK_NAV_LEFT = "list_widget.ACTION_WIDGET_CLICK_NAV_LEFT";
private static final String ACTION_WIDGET_CLICK_NAV_RIGHT = "list_widget.ACTION_WIDGET_CLICK_NAV_RIGHT"; private static final String ACTION_WIDGET_CLICK_NAV_RIGHT = "list_widget.ACTION_WIDGET_CLICK_NAV_RIGHT";
private static final String ACTION_WIDGET_CLICK_NAV_TODAY = "list_widget.ACTION_WIDGET_CLICK_NAV_TODAY"; private static final String ACTION_WIDGET_CLICK_NAV_TODAY = "list_widget.ACTION_WIDGET_CLICK_NAV_TODAY";
private static final String ACTION_WIDGET_CLICK_NAV_REFRESH = "list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH"; private static final String ACTION_WIDGET_CLICK_NAV_REFRESH = "list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH";
private static final String ACTION_WIDGET_CLICK_BUY_PREMIUM = "list_widget.ACTION_WIDGET_CLICK_BUY_PREMIUM"; private static final String ACTION_WIDGET_CLICK_BUY_PREMIUM = "list_widget.ACTION_WIDGET_CLICK_BUY_PREMIUM";
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, SharedPreferences widgetData) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, SharedPreferences widgetData) {
for (int i = 0; i < appWidgetIds.length; i++) { for (int i = 0; i < appWidgetIds.length; i++) {
RemoteViews views = generateView(context, appWidgetIds[i]); RemoteViews views = generateView(context, appWidgetIds[i]);
if(premiumEnabled(context) && userLoggedIn(context)) { if(premiumEnabled(context) && userLoggedIn(context)) {
int rday = selectDay(context, appWidgetIds[i], 0, true); int rday = selectDay(context, appWidgetIds[i], 0, true);
views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday));
} }
pushUpdate(context, views, appWidgetIds[i]); pushUpdate(context, views, appWidgetIds[i]);
} }
} }
public static void pushUpdate(Context context, RemoteViews remoteViews, int appWidgetSingleId) { public static void pushUpdate(Context context, RemoteViews remoteViews, int appWidgetSingleId) {
AppWidgetManager manager = AppWidgetManager.getInstance(context); AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(appWidgetSingleId, remoteViews); manager.updateAppWidget(appWidgetSingleId, remoteViews);
manager.notifyAppWidgetViewDataChanged(appWidgetSingleId, R.id.widget_list); manager.notifyAppWidgetViewDataChanged(appWidgetSingleId, R.id.widget_list);
} }
public static RemoteViews generateView(Context context, int appId) { public static RemoteViews generateView(Context context, int appId) {
Intent serviceIntent = new Intent(context, WidgetTimetableService.class); Intent serviceIntent = new Intent(context, WidgetTimetableService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId); serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId);
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_timetable); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_timetable);
views.setViewVisibility(R.id.need_premium, View.GONE); views.setViewVisibility(R.id.need_premium, View.GONE);
views.setViewVisibility(R.id.need_login, View.GONE); views.setViewVisibility(R.id.need_login, View.GONE);
views.setViewVisibility(R.id.tt_grid_cont, View.GONE); views.setViewVisibility(R.id.tt_grid_cont, View.GONE);
if(!userLoggedIn(context)) { if(!userLoggedIn(context)) {
views.setViewVisibility(R.id.need_login, View.VISIBLE); views.setViewVisibility(R.id.need_login, View.VISIBLE);
views.setOnClickPendingIntent(R.id.open_login, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); views.setOnClickPendingIntent(R.id.open_login, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId));
} else if(premiumEnabled(context)) { } else if(premiumEnabled(context)) {
views.setViewVisibility(R.id.tt_grid_cont, View.VISIBLE); views.setViewVisibility(R.id.tt_grid_cont, View.VISIBLE);
views.setOnClickPendingIntent(R.id.nav_to_left, makePending(context, ACTION_WIDGET_CLICK_NAV_LEFT, appId)); views.setOnClickPendingIntent(R.id.nav_to_left, makePending(context, ACTION_WIDGET_CLICK_NAV_LEFT, appId));
views.setOnClickPendingIntent(R.id.nav_to_right, makePending(context, ACTION_WIDGET_CLICK_NAV_RIGHT, appId)); views.setOnClickPendingIntent(R.id.nav_to_right, makePending(context, ACTION_WIDGET_CLICK_NAV_RIGHT, appId));
views.setOnClickPendingIntent(R.id.nav_current, makePending(context, ACTION_WIDGET_CLICK_NAV_TODAY, appId)); views.setOnClickPendingIntent(R.id.nav_current, makePending(context, ACTION_WIDGET_CLICK_NAV_TODAY, appId));
views.setOnClickPendingIntent(R.id.nav_refresh, makePending(context, ACTION_WIDGET_CLICK_NAV_REFRESH, appId)); views.setOnClickPendingIntent(R.id.nav_refresh, makePending(context, ACTION_WIDGET_CLICK_NAV_REFRESH, appId));
views.setRemoteAdapter(R.id.widget_list, serviceIntent); views.setRemoteAdapter(R.id.widget_list, serviceIntent);
views.setEmptyView(R.id.widget_list, R.id.empty_view); views.setEmptyView(R.id.widget_list, R.id.empty_view);
} else { } else {
views.setViewVisibility(R.id.need_premium, View.VISIBLE); views.setViewVisibility(R.id.need_premium, View.VISIBLE);
views.setOnClickPendingIntent(R.id.buy_premium, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); views.setOnClickPendingIntent(R.id.buy_premium, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId));
} }
return views; return views;
} }
static PendingIntent makePending(Context context, String action, int appWidgetId) { static PendingIntent makePending(Context context, String action, int appWidgetId) {
Intent activebtnnext = new Intent(context, WidgetTimetable.class); Intent activebtnnext = new Intent(context, WidgetTimetable.class);
activebtnnext.setAction(action); activebtnnext.setAction(action);
activebtnnext.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); activebtnnext.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
return PendingIntent.getBroadcast(context, appWidgetId, activebtnnext , PendingIntent.FLAG_IMMUTABLE); return PendingIntent.getBroadcast(context, appWidgetId, activebtnnext , PendingIntent.FLAG_IMMUTABLE);
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent); super.onReceive(context, intent);
if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
int appId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); int appId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
RemoteViews views = generateView(context, appId); RemoteViews views = generateView(context, appId);
try { try {
if(premiumEnabled(context) && userLoggedIn(context)) { if(premiumEnabled(context) && userLoggedIn(context)) {
if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_LEFT)) { if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_LEFT)) {
int rday = selectDay(context, appId, -1, false); int rday = selectDay(context, appId, -1, false);
views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday));
pushUpdate(context, views, appId); pushUpdate(context, views, appId);
} else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_RIGHT)) { } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_RIGHT)) {
int rday = selectDay(context, appId, 1, false); int rday = selectDay(context, appId, 1, false);
views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday));
pushUpdate(context, views, appId); pushUpdate(context, views, appId);
} else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_TODAY)) { } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_TODAY)) {
int rday = getToday(context); int rday = getToday(context);
setSelectedDay(context, appId, rday); setSelectedDay(context, appId, rday);
views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday));
pushUpdate(context, views, appId); pushUpdate(context, views, appId);
} else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_REFRESH)) { } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_REFRESH)) {
PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("timetable://refresh")); PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("timetable://refresh"));
pendingIntent.send(); pendingIntent.send();
} else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_DELETED")) { } else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_DELETED")) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
dbManager.deleteWidget(appId); dbManager.deleteWidget(appId);
dbManager.close(); dbManager.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
if(intent.getAction().equals(ACTION_WIDGET_CLICK_BUY_PREMIUM)) { if(intent.getAction().equals(ACTION_WIDGET_CLICK_BUY_PREMIUM)) {
PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("settings://premium")); PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("settings://premium"));
pendingIntent.send(); pendingIntent.send();
} }
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
public static String convertDayOfWeek(Context context, int rday) { public static String convertDayOfWeek(Context context, int rday) {
/*if(rday == -1) return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, new Locale("hu", "HU")); /*if(rday == -1) return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, new Locale("hu", "HU"));
String dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, new Locale("hu", "HU"));*/ String dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, new Locale("hu", "HU"));*/
String dayOfWeek = "Unknown"; String dayOfWeek = "Unknown";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Locale loc = getLocale(context); Locale loc = getLocale(context);
if (rday == -1) if (rday == -1)
return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, loc); return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, loc);
dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, loc); dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, loc);
} }
return dayOfWeek.substring(0, 1).toUpperCase() + dayOfWeek.substring(1).toLowerCase(); return dayOfWeek.substring(0, 1).toUpperCase() + dayOfWeek.substring(1).toLowerCase();
} }
public static void setSelectedDay(Context context, int wid, int day) { public static void setSelectedDay(Context context, int wid, int day) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
dbManager.update(wid, day); dbManager.update(wid, day);
dbManager.close(); dbManager.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static int getToday(Context context) { public static int getToday(Context context) {
int rday = new DateTime().getDayOfWeek() - 1; int rday = new DateTime().getDayOfWeek() - 1;
List<JSONArray> s = genJsonDays(context); List<JSONArray> s = genJsonDays(context);
try { try {
if(checkIsAfter(s, rday)) rday += 1; if(checkIsAfter(s, rday)) rday += 1;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return retDay(rday, s.size()); return retDay(rday, s.size());
} }
public static int selectDay(Context context, int wid, int add, Boolean afterSubjects) { public static int selectDay(Context context, int wid, int add, Boolean afterSubjects) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
Cursor cursor = dbManager.fetchWidget(wid); Cursor cursor = dbManager.fetchWidget(wid);
List<JSONArray> s = genJsonDays(context); List<JSONArray> s = genJsonDays(context);
int retday = new DateTime().getDayOfWeek() - 1; int retday = new DateTime().getDayOfWeek() - 1;
if(cursor.getCount() != 0) retday = retDay(cursor.getInt(1) + add, s.size()); if(cursor.getCount() != 0) retday = retDay(cursor.getInt(1) + add, s.size());
if(afterSubjects) if(checkIsAfter(s, retday)) retday += 1; if(afterSubjects) if(checkIsAfter(s, retday)) retday += 1;
retday = retDay(retday, s.size()); retday = retDay(retday, s.size());
if(cursor.getCount() == 0) dbManager.insertSelDay(wid, retday); if(cursor.getCount() == 0) dbManager.insertSelDay(wid, retday);
else dbManager.update(wid, retday); else dbManager.update(wid, retday);
dbManager.close(); dbManager.close();
return retday; return retday;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return 0; return 0;
} }
public static Boolean checkIsAfter(List<JSONArray> s, int retday) throws Exception { public static Boolean checkIsAfter(List<JSONArray> s, int retday) throws Exception {
retday = retDay(retday, s.size()); retday = retDay(retday, s.size());
String vegIdopont = s.get(retday).getJSONObject(s.get(retday).length() - 1).getString("VegIdopont"); String vegIdopont = s.get(retday).getJSONObject(s.get(retday).length() - 1).getString("VegIdopont");
return new DateTime().isAfter(new DateTime(vegIdopont)); return new DateTime().isAfter(new DateTime(vegIdopont));
} }
public static int retDay(int retday, int size) { public static int retDay(int retday, int size) {
if (retday < 0) retday = size - 1; if (retday < 0) retday = size - 1;
else if (retday > size - 1) retday = 0; else if (retday > size - 1) retday = 0;
return retday; return retday;
} }
public static List<JSONArray> genJsonDays(Context context) { public static List<JSONArray> genJsonDays(Context context) {
List<JSONArray> gen_days = new ArrayList<>(); List<JSONArray> gen_days = new ArrayList<>();
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
Cursor ct = dbManager.fetchTimetable(); Cursor ct = dbManager.fetchTimetable();
dbManager.close(); dbManager.close();
if(ct.getCount() == 0) { if(ct.getCount() == 0) {
return gen_days; return gen_days;
} }
JSONObject fecthtt = new JSONObject(ct.getString(0)); JSONObject fecthtt = new JSONObject(ct.getString(0));
JSONArray dayArray = new JSONArray(); JSONArray dayArray = new JSONArray();
String currday = ""; String currday = "";
String currweek = String.valueOf(Week.current().id()); String currweek = String.valueOf(Week.current().id());
JSONArray week = fecthtt.getJSONArray(currweek); JSONArray week = fecthtt.getJSONArray(currweek);
for (int i=0; i < week.length(); i++) for (int i=0; i < week.length(); i++)
{ {
try { try {
if(i == 0) currday = week.getJSONObject(0).getString("Datum"); if(i == 0) currday = week.getJSONObject(0).getString("Datum");
JSONObject oraObj = week.getJSONObject(i); JSONObject oraObj = week.getJSONObject(i);
if(!currday.equals(oraObj.getString("Datum"))) { if(!currday.equals(oraObj.getString("Datum"))) {
gen_days.add(dayArray); gen_days.add(dayArray);
currday = week.getJSONObject(i).getString("Datum"); currday = week.getJSONObject(i).getString("Datum");
dayArray = new JSONArray(); dayArray = new JSONArray();
} }
dayArray.put(oraObj); dayArray.put(oraObj);
if(i == week.length() - 1) { if(i == week.length() - 1) {
gen_days.add(dayArray); gen_days.add(dayArray);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
Collections.sort(gen_days, new Comparator<JSONArray>() { Collections.sort(gen_days, new Comparator<JSONArray>() {
public int compare(JSONArray a, JSONArray b) { public int compare(JSONArray a, JSONArray b) {
long valA = 0; long valA = 0;
long valB = 0; long valB = 0;
try { try {
valA = (long) new DateTime( a.getJSONObject(0).getString("Datum")).getMillis(); valA = (long) new DateTime( a.getJSONObject(0).getString("Datum")).getMillis();
valB = (long) new DateTime( b.getJSONObject(0).getString("Datum")).getMillis(); valB = (long) new DateTime( b.getJSONObject(0).getString("Datum")).getMillis();
} }
catch (JSONException ignored) { catch (JSONException ignored) {
} }
return (int) (valA - valB); return (int) (valA - valB);
} }
}); });
return gen_days; return gen_days;
} }
public static String zeroPad(int value, int padding){ public static String zeroPad(int value, int padding){
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(value); b.append(value);
while(b.length() < padding){ while(b.length() < padding){
b.insert(0,"0"); b.insert(0,"0");
} }
return b.toString(); return b.toString();
} }
public static Locale getLocale(Context context) { public static Locale getLocale(Context context) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
String loc = dbManager.fetchLocale().getString(0); String loc = dbManager.fetchLocale().getString(0);
dbManager.close(); dbManager.close();
if(loc.equals("hu") || loc.equals("de")) { if(loc.equals("hu") || loc.equals("de")) {
return new Locale(loc, loc.toUpperCase()); return new Locale(loc, loc.toUpperCase());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return new Locale("en", "GB"); return new Locale("en", "GB");
} }
public static boolean premiumEnabled(Context context) { public static boolean premiumEnabled(Context context) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
String premium_token = dbManager.fetchPremiumToken().getString(0); String premium_token = dbManager.fetchPremiumToken().getString(0);
String premium_scopes_raw = dbManager.fetchPremiumScopes().getString(0); String premium_scopes_raw = dbManager.fetchPremiumScopes().getString(0);
dbManager.close(); dbManager.close();
JSONArray arr = new JSONArray(premium_scopes_raw); JSONArray arr = new JSONArray(premium_scopes_raw);
List<String> premium_scopes = new ArrayList<>(); List<String> premium_scopes = new ArrayList<>();
for(int i = 0; i < arr.length(); i++){ for(int i = 0; i < arr.length(); i++){
String scope = arr.getString(i); String scope = arr.getString(i);
premium_scopes.add(scope.substring(scope.lastIndexOf('.') + 1)); premium_scopes.add(scope.substring(scope.lastIndexOf('.') + 1));
} }
if(!premium_token.equals("") && (premium_scopes.contains("*") || premium_scopes.contains("TIMETALBE_WIDGET"))) { if(!premium_token.equals("") && (premium_scopes.contains("*") || premium_scopes.contains("TIMETALBE_WIDGET"))) {
return true; return true;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return false; return false;
} }
public static boolean userLoggedIn(Context context) { public static boolean userLoggedIn(Context context) {
return !lastUserId(context).equals(""); return !lastUserId(context).equals("");
} }
public static String lastUserId(Context context) { public static String lastUserId(Context context) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
Cursor cursor = dbManager.fetchLastUser(); Cursor cursor = dbManager.fetchLastUser();
dbManager.close(); dbManager.close();
if(cursor != null && !cursor.getString(0).equals("")) { if(cursor != null && !cursor.getString(0).equals("")) {
String last_user = cursor.getString(0); String last_user = cursor.getString(0);
return last_user; return last_user;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return ""; return "";
} }
@Override @Override
public void onEnabled(Context context) { public void onEnabled(Context context) {
} }
@Override @Override
public void onDisabled(Context context) { public void onDisabled(Context context) {
} }
} }

View File

@ -1,354 +1,354 @@
package hu.refilc.naplo.widget_timetable; package hu.refilc.naplo.widget_timetable;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import hu.refilc.naplo.database.DBManager; import hu.refilc.naplo.database.DBManager;
import hu.refilc.naplo.R; import hu.refilc.naplo.R;
public class WidgetTimetableDataProvider implements RemoteViewsService.RemoteViewsFactory { public class WidgetTimetableDataProvider implements RemoteViewsService.RemoteViewsFactory {
private Context context; private Context context;
private int appWidgetId; private int appWidgetId;
private int rday = 0; private int rday = 0;
private int theme; private int theme;
private Integer[] colorValues; private Integer[] colorValues;
List<Lesson> day_subjects = new ArrayList<>(); List<Lesson> day_subjects = new ArrayList<>();
List<Integer> lessonIndexes = new ArrayList<>(); List<Integer> lessonIndexes = new ArrayList<>();
Item witem; Item witem;
/* Default values */ /* Default values */
static class Item { static class Item {
int Layout; int Layout;
int NumVisibility; int NumVisibility;
int NameVisibility; int NameVisibility;
int NameNodescVisibility; int NameNodescVisibility;
int DescVisibility; int DescVisibility;
int RoomVisibility; int RoomVisibility;
int TimeVisibility; int TimeVisibility;
int NumColor; int NumColor;
int NameColor; int NameColor;
int NameNodescColor; int NameNodescColor;
int DescColor; int DescColor;
Integer[] NameNodescPadding = {0, 0, 0, 0}; Integer[] NameNodescPadding = {0, 0, 0, 0};
public Item(int Layout, int NumVisibility,int NameVisibility,int NameNodescVisibility,int DescVisibility,int RoomVisibility,int TimeVisibility,int NumColor,int NameColor,int NameNodescColor,int DescColor) { public Item(int Layout, int NumVisibility,int NameVisibility,int NameNodescVisibility,int DescVisibility,int RoomVisibility,int TimeVisibility,int NumColor,int NameColor,int NameNodescColor,int DescColor) {
this.Layout = Layout; this.Layout = Layout;
this.NumVisibility = NumVisibility; this.NumVisibility = NumVisibility;
this.NameVisibility = NameVisibility; this.NameVisibility = NameVisibility;
this.NameNodescVisibility = NameNodescVisibility; this.NameNodescVisibility = NameNodescVisibility;
this.DescVisibility = DescVisibility; this.DescVisibility = DescVisibility;
this.RoomVisibility = RoomVisibility; this.RoomVisibility = RoomVisibility;
this.TimeVisibility = TimeVisibility; this.TimeVisibility = TimeVisibility;
this.NumColor = NumColor; this.NumColor = NumColor;
this.NameColor = NameColor; this.NameColor = NameColor;
this.NameNodescColor = NameNodescColor; this.NameNodescColor = NameNodescColor;
this.DescColor = DescColor; this.DescColor = DescColor;
} }
} }
static class Lesson { static class Lesson {
String status; String status;
String lessonIndex; String lessonIndex;
String lessonName; String lessonName;
String lessonTopic; String lessonTopic;
String lessonRoom; String lessonRoom;
long lessonStart; long lessonStart;
long lessonEnd; long lessonEnd;
String substituteTeacher; String substituteTeacher;
public Lesson(String status, String lessonIndex,String lessonName,String lessonTopic, String lessonRoom,long lessonStart,long lessonEnd,String substituteTeacher) { public Lesson(String status, String lessonIndex,String lessonName,String lessonTopic, String lessonRoom,long lessonStart,long lessonEnd,String substituteTeacher) {
this.status = status; this.status = status;
this.lessonIndex = lessonIndex; this.lessonIndex = lessonIndex;
this.lessonName = lessonName; this.lessonName = lessonName;
this.lessonTopic = lessonTopic; this.lessonTopic = lessonTopic;
this.lessonRoom = lessonRoom; this.lessonRoom = lessonRoom;
this.lessonStart = lessonStart; this.lessonStart = lessonStart;
this.lessonEnd = lessonEnd; this.lessonEnd = lessonEnd;
this.substituteTeacher = substituteTeacher; this.substituteTeacher = substituteTeacher;
} }
} }
Integer[] itemNameNodescPadding = {0, 0, 0, 0}; Integer[] itemNameNodescPadding = {0, 0, 0, 0};
public WidgetTimetableDataProvider(Context context, Intent intent) { public WidgetTimetableDataProvider(Context context, Intent intent) {
this.context = context; this.context = context;
this.appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); this.appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
this.theme = getThemeAccent(context); this.theme = getThemeAccent(context);
this.colorValues = new Integer[]{R.color.filc, this.colorValues = new Integer[]{R.color.filc,
R.color.blue_shade300, R.color.blue_shade300,
R.color.green_shade300, R.color.green_shade300,
R.color.lime_shade300, R.color.lime_shade300,
R.color.yellow_shade300, R.color.yellow_shade300,
R.color.orange_shade300, R.color.orange_shade300,
R.color.red_shade300, R.color.red_shade300,
R.color.pink_shade300, R.color.pink_shade300,
R.color.purple_shade300}; R.color.purple_shade300};
} }
@Override @Override
public void onCreate() { public void onCreate() {
initData(); initData();
} }
@Override @Override
public void onDataSetChanged() { public void onDataSetChanged() {
initData(); initData();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
} }
@Override @Override
public int getCount() { public int getCount() {
return day_subjects.size(); return day_subjects.size();
} }
public void setLayout(final RemoteViews view) { public void setLayout(final RemoteViews view) {
/* Visibilities */ /* Visibilities */
view.setViewVisibility(R.id.tt_item_num, witem.NumVisibility); view.setViewVisibility(R.id.tt_item_num, witem.NumVisibility);
view.setViewVisibility(R.id.tt_item_name, witem.NameVisibility); view.setViewVisibility(R.id.tt_item_name, witem.NameVisibility);
view.setViewVisibility(R.id.tt_item_name_nodesc, witem.NameNodescVisibility); view.setViewVisibility(R.id.tt_item_name_nodesc, witem.NameNodescVisibility);
view.setViewVisibility(R.id.tt_item_desc, witem.DescVisibility); view.setViewVisibility(R.id.tt_item_desc, witem.DescVisibility);
view.setViewVisibility(R.id.tt_item_room, witem.RoomVisibility); view.setViewVisibility(R.id.tt_item_room, witem.RoomVisibility);
view.setViewVisibility(R.id.tt_item_time, witem.TimeVisibility); view.setViewVisibility(R.id.tt_item_time, witem.TimeVisibility);
/* backgroundResources */ /* backgroundResources */
view.setInt(R.id.main_lay, "setBackgroundResource", witem.Layout); view.setInt(R.id.main_lay, "setBackgroundResource", witem.Layout);
/* Paddings */ /* Paddings */
view.setViewPadding(R.id.tt_item_name_nodesc, witem.NameNodescPadding[0], witem.NameNodescPadding[1], witem.NameNodescPadding[2], witem.NameNodescPadding[3]); view.setViewPadding(R.id.tt_item_name_nodesc, witem.NameNodescPadding[0], witem.NameNodescPadding[1], witem.NameNodescPadding[2], witem.NameNodescPadding[3]);
/* Text Colors */ /* Text Colors */
view.setInt(R.id.tt_item_num, "setTextColor", getColor(context, witem.NumColor)); view.setInt(R.id.tt_item_num, "setTextColor", getColor(context, witem.NumColor));
view.setInt(R.id.tt_item_name, "setTextColor", getColor(context, witem.NameColor)); view.setInt(R.id.tt_item_name, "setTextColor", getColor(context, witem.NameColor));
view.setInt(R.id.tt_item_name_nodesc, "setTextColor", getColor(context, witem.NameNodescColor)); view.setInt(R.id.tt_item_name_nodesc, "setTextColor", getColor(context, witem.NameNodescColor));
view.setInt(R.id.tt_item_desc, "setTextColor", getColor(context, witem.DescColor)); view.setInt(R.id.tt_item_desc, "setTextColor", getColor(context, witem.DescColor));
} }
public int getColor(Context context, int color) { public int getColor(Context context, int color) {
return context.getResources().getColor(color); return context.getResources().getColor(color);
} }
@Override @Override
public RemoteViews getViewAt(int position) { public RemoteViews getViewAt(int position) {
RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.timetable_item); RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.timetable_item);
witem = defaultItem(theme); witem = defaultItem(theme);
Lesson curr_subject = day_subjects.get(position); Lesson curr_subject = day_subjects.get(position);
if (curr_subject.status.equals("empty")) { if (curr_subject.status.equals("empty")) {
witem.NumColor = R.color.text_miss_num; witem.NumColor = R.color.text_miss_num;
witem.TimeVisibility = View.GONE; witem.TimeVisibility = View.GONE;
witem.RoomVisibility = View.GONE; witem.RoomVisibility = View.GONE;
witem.NameNodescColor = R.color.text_miss; witem.NameNodescColor = R.color.text_miss;
} }
if (!curr_subject.substituteTeacher.equals("null")) { if (!curr_subject.substituteTeacher.equals("null")) {
witem.NumColor = R.color.yellow; witem.NumColor = R.color.yellow;
witem.Layout = R.drawable.card_layout_tile_helyetesitett; witem.Layout = R.drawable.card_layout_tile_helyetesitett;
} }
if (curr_subject.status.equals("Elmaradt")) { if (curr_subject.status.equals("Elmaradt")) {
witem.NumColor = R.color.red; witem.NumColor = R.color.red;
witem.Layout = R.drawable.card_layout_tile_elmarad; witem.Layout = R.drawable.card_layout_tile_elmarad;
} else if (curr_subject.status.equals("TanevRendjeEsemeny")) { } else if (curr_subject.status.equals("TanevRendjeEsemeny")) {
witem.NumVisibility = View.GONE; witem.NumVisibility = View.GONE;
witem.TimeVisibility = View.GONE; witem.TimeVisibility = View.GONE;
witem.RoomVisibility = View.GONE; witem.RoomVisibility = View.GONE;
witem.NameNodescPadding[0] = 50; witem.NameNodescPadding[0] = 50;
witem.NameNodescPadding[2] = 50; witem.NameNodescPadding[2] = 50;
witem.NameNodescColor = R.color.text_miss; witem.NameNodescColor = R.color.text_miss;
} }
if (curr_subject.lessonTopic.equals("null")) { if (curr_subject.lessonTopic.equals("null")) {
witem.DescVisibility = View.GONE; witem.DescVisibility = View.GONE;
witem.NameVisibility = View.GONE; witem.NameVisibility = View.GONE;
witem.NameNodescVisibility = View.VISIBLE; witem.NameNodescVisibility = View.VISIBLE;
} }
setLayout(view); setLayout(view);
String lessonIndexTrailing = curr_subject.lessonIndex.equals("+") ? "" : "."; String lessonIndexTrailing = curr_subject.lessonIndex.equals("+") ? "" : ".";
view.setTextViewText(R.id.tt_item_num, curr_subject.lessonIndex + lessonIndexTrailing); view.setTextViewText(R.id.tt_item_num, curr_subject.lessonIndex + lessonIndexTrailing);
view.setTextViewText(R.id.tt_item_name, curr_subject.lessonName); view.setTextViewText(R.id.tt_item_name, curr_subject.lessonName);
view.setTextViewText(R.id.tt_item_name_nodesc, curr_subject.lessonName); view.setTextViewText(R.id.tt_item_name_nodesc, curr_subject.lessonName);
view.setTextViewText(R.id.tt_item_desc, curr_subject.lessonTopic); view.setTextViewText(R.id.tt_item_desc, curr_subject.lessonTopic);
view.setTextViewText(R.id.tt_item_room, curr_subject.lessonRoom); view.setTextViewText(R.id.tt_item_room, curr_subject.lessonRoom);
if(curr_subject.lessonStart != 0 && curr_subject.lessonEnd != 0) if(curr_subject.lessonStart != 0 && curr_subject.lessonEnd != 0)
view.setTextViewText(R.id.tt_item_time, WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonStart).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonStart).getMinuteOfHour(), 2) + view.setTextViewText(R.id.tt_item_time, WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonStart).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonStart).getMinuteOfHour(), 2) +
"\n" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getMinuteOfHour(),2)); "\n" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getMinuteOfHour(),2));
return view; return view;
} }
@Override @Override
public RemoteViews getLoadingView() { public RemoteViews getLoadingView() {
return null; return null;
} }
@Override @Override
public int getViewTypeCount() { public int getViewTypeCount() {
return 1; return 1;
} }
@Override @Override
public long getItemId(int position) { public long getItemId(int position) {
return position; return position;
} }
@Override @Override
public boolean hasStableIds() { public boolean hasStableIds() {
return true; return true;
} }
private void initData() { private void initData() {
theme = getThemeAccent(context); theme = getThemeAccent(context);
rday = WidgetTimetable.selectDay(context, appWidgetId, 0, false); rday = WidgetTimetable.selectDay(context, appWidgetId, 0, false);
day_subjects.clear(); day_subjects.clear();
lessonIndexes.clear(); lessonIndexes.clear();
try { try {
List<JSONArray> arr = WidgetTimetable.genJsonDays(context); List<JSONArray> arr = WidgetTimetable.genJsonDays(context);
if(arr.isEmpty()) { if(arr.isEmpty()) {
return; return;
} }
JSONArray arr_lessons = WidgetTimetable.genJsonDays(context).get(rday); JSONArray arr_lessons = WidgetTimetable.genJsonDays(context).get(rday);
for (int i = 0; i < arr_lessons.length(); i++) { for (int i = 0; i < arr_lessons.length(); i++) {
JSONObject obj_lessons = arr_lessons.getJSONObject(i); JSONObject obj_lessons = arr_lessons.getJSONObject(i);
day_subjects.add(jsonToLesson(obj_lessons)); day_subjects.add(jsonToLesson(obj_lessons));
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
if(day_subjects.size() > 0) { if(day_subjects.size() > 0) {
Collections.sort(day_subjects, new Comparator<Lesson>() { Collections.sort(day_subjects, new Comparator<Lesson>() {
public int compare(Lesson o1, Lesson o2) { public int compare(Lesson o1, Lesson o2) {
return new DateTime(o1.lessonStart).compareTo(new DateTime(o2.lessonStart)); return new DateTime(o1.lessonStart).compareTo(new DateTime(o2.lessonStart));
} }
}); });
for (int i = 0; i < day_subjects.size(); i++) { for (int i = 0; i < day_subjects.size(); i++) {
if(!day_subjects.get(i).lessonIndex.equals("+")) { if(!day_subjects.get(i).lessonIndex.equals("+")) {
lessonIndexes.add(Integer.valueOf(day_subjects.get(i).lessonIndex)); lessonIndexes.add(Integer.valueOf(day_subjects.get(i).lessonIndex));
} }
} }
if(lessonIndexes.size() > 0) { if(lessonIndexes.size() > 0) {
int lessonsChecked = Collections.min(lessonIndexes); int lessonsChecked = Collections.min(lessonIndexes);
int i = 0; int i = 0;
while(lessonsChecked < Collections.max(lessonIndexes)) { while(lessonsChecked < Collections.max(lessonIndexes)) {
if(!lessonIndexes.contains(lessonsChecked)) { if(!lessonIndexes.contains(lessonsChecked)) {
day_subjects.add(i, emptyLesson(lessonsChecked)); day_subjects.add(i, emptyLesson(lessonsChecked));
} }
lessonsChecked++; lessonsChecked++;
i++; i++;
} }
} }
} }
} }
public static Integer getThemeAccent(Context context) { public static Integer getThemeAccent(Context context) {
DBManager dbManager = new DBManager(context.getApplicationContext()); DBManager dbManager = new DBManager(context.getApplicationContext());
try { try {
dbManager.open(); dbManager.open();
Cursor cursor = dbManager.fetchTheme(); Cursor cursor = dbManager.fetchTheme();
dbManager.close(); dbManager.close();
return cursor.getInt(1); return cursor.getInt(1);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return 0; return 0;
} }
public Item defaultItem(int theme) { public Item defaultItem(int theme) {
return new Item( return new Item(
R.drawable.card_layout_tile, R.drawable.card_layout_tile,
View.VISIBLE, View.VISIBLE,
View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE,
View.VISIBLE, View.VISIBLE,
View.VISIBLE, View.VISIBLE,
colorValues[theme >= colorValues.length ? 0 : theme], colorValues[theme >= colorValues.length ? 0 : theme],
R.color.text, R.color.text,
R.color.text, R.color.text,
R.color.text_desc R.color.text_desc
); );
} }
public Lesson emptyLesson(int lessonIndex) { public Lesson emptyLesson(int lessonIndex) {
return new Lesson("empty", String.valueOf(lessonIndex), "Lyukasóra", "null", "null", 0, 0, "null"); return new Lesson("empty", String.valueOf(lessonIndex), "Lyukasóra", "null", "null", 0, 0, "null");
} }
public Lesson jsonToLesson(JSONObject json) { public Lesson jsonToLesson(JSONObject json) {
try { try {
return new Lesson( return new Lesson(
json.getJSONObject("Allapot").getString("Nev"), json.getJSONObject("Allapot").getString("Nev"),
!json.getString("Oraszam").equals("null") ? json.getString("Oraszam") : "+", !json.getString("Oraszam").equals("null") ? json.getString("Oraszam") : "+",
json.getString("Nev"), json.getString("Nev"),
json.getString("Tema"), json.getString("Tema"),
json.getString("TeremNeve"), json.getString("TeremNeve"),
new DateTime(json.getString("KezdetIdopont")).getMillis(), new DateTime(json.getString("KezdetIdopont")).getMillis(),
new DateTime(json.getString("VegIdopont")).getMillis(), new DateTime(json.getString("VegIdopont")).getMillis(),
json.getString("HelyettesTanarNeve") json.getString("HelyettesTanarNeve")
); );
}catch (Exception e) { }catch (Exception e) {
Log.d("Filc", "exception: " + e); Log.d("Filc", "exception: " + e);
}; };
return null; return null;
} }
} }

View File

@ -1,12 +1,12 @@
package hu.refilc.naplo.widget_timetable; package hu.refilc.naplo.widget_timetable;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
public class WidgetTimetableService extends RemoteViewsService { public class WidgetTimetableService extends RemoteViewsService {
@Override @Override
public RemoteViewsFactory onGetViewFactory(Intent intent) { public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new WidgetTimetableDataProvider(getApplicationContext(), intent); return new WidgetTimetableDataProvider(getApplicationContext(), intent);
} }
} }

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:id="@+id/main_lay" android:id="@+id/main_lay"
android:layout_height="50dp" android:layout_height="50dp"
@ -15,12 +16,14 @@
android:id="@+id/tt_item_num" android:id="@+id/tt_item_num"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fontFamily="@font/montserrat_medium"
android:gravity="center"
android:text="1."
android:textColor="@color/filc"
android:textColorLink="#ff3D7BF4"
android:textSize="30sp" android:textSize="30sp"
android:textStyle="bold" android:textStyle="bold"
android:fontFamily="@font/montserrat_medium" tools:ignore="HardcodedText" />
android:text="1."
android:gravity="center"
android:textColor="@color/filc"></TextView>
<TextView <TextView
android:id="@+id/tt_item_name" android:id="@+id/tt_item_name"
@ -33,10 +36,11 @@
android:text="Óra neve" android:text="Óra neve"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:layout_toLeftOf="@id/tt_item_room" android:layout_toStartOf="@id/tt_item_room"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_toRightOf="@id/tt_item_num" android:layout_toEndOf="@id/tt_item_num"
android:textColor="@color/text"></TextView> android:textColor="@color/text"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/tt_item_name_nodesc" android:id="@+id/tt_item_name_nodesc"
@ -47,13 +51,14 @@
android:fontFamily="@font/montserrat_medium" android:fontFamily="@font/montserrat_medium"
android:visibility="gone" android:visibility="gone"
android:layout_marginTop="2.5dp" android:layout_marginTop="2.5dp"
android:layout_toLeftOf="@id/tt_item_room" android:layout_toStartOf="@id/tt_item_room"
android:text="Óra neve" android:text="Óra neve"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_toRightOf="@id/tt_item_num" android:layout_toEndOf="@id/tt_item_num"
android:textColor="@color/text"></TextView> android:textColor="@color/text"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/tt_item_desc" android:id="@+id/tt_item_desc"
@ -67,10 +72,11 @@
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_toRightOf="@id/tt_item_num" android:layout_toEndOf="@id/tt_item_num"
android:layout_toLeftOf="@id/tt_item_room" android:layout_toStartOf="@id/tt_item_room"
android:layout_below="@id/tt_item_name" android:layout_below="@id/tt_item_name"
android:textColor="@color/text_desc"></TextView> android:textColor="@color/text_desc"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/tt_item_room" android:id="@+id/tt_item_room"
@ -84,8 +90,9 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="2" android:maxLines="2"
android:gravity="center" android:gravity="center"
android:layout_toLeftOf="@id/tt_item_time" android:layout_toStartOf="@id/tt_item_time"
android:textColor="@color/text_desc"></TextView> android:textColor="@color/text_desc"
tools:ignore="HardcodedText" />
<TextView <TextView
android:id="@+id/tt_item_time" android:id="@+id/tt_item_time"
@ -95,11 +102,12 @@
android:textFontWeight="500" android:textFontWeight="500"
android:fontFamily="@font/montserrat_medium" android:fontFamily="@font/montserrat_medium"
android:textStyle="bold" android:textStyle="bold"
android:layout_marginLeft="2dp" android:layout_marginStart="2dp"
android:layout_marginTop="-2dp" android:layout_marginTop="-2dp"
android:text="8:30\n9:10" android:text="8:30\n9:10"
android:gravity="center" android:gravity="center"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:textColor="@color/white"></TextView> android:textColor="@color/white"
tools:ignore="HardcodedText" />
</RelativeLayout> </RelativeLayout>

View File

@ -19,10 +19,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:text="Empty" android:text="Üres / Empty"
android:background="@drawable/widget_card_bottom_dark"
android:textColor="@color/text" android:textColor="@color/text"
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
<ListView <ListView
android:id="@+id/widget_list" android:id="@+id/widget_list"
@ -43,57 +45,63 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="45dp" android:layout_height="45dp"
android:background="@drawable/widget_card_top_dark"> android:background="@drawable/widget_card_top_dark">
<ImageView <ImageView
android:id="@+id/nav_refresh" android:id="@+id/nav_refresh"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_toStartOf="@id/nav_to_left"
android:clickable="true" android:clickable="true"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
android:padding="10dp"
android:src="@drawable/ic_refresh_cw" android:src="@drawable/ic_refresh_cw"
android:layout_toLeftOf="@id/nav_to_left"
android:tint="@color/text_desc" android:tint="@color/text_desc"
tools:ignore="UseAppTint" tools:ignore="UseAppTint"
android:padding="10dp" /> android:focusable="true" />
<ImageView <ImageView
android:id="@+id/nav_to_left" android:id="@+id/nav_to_left"
android:layout_width="50dp" android:layout_width="45dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_toStartOf="@id/nav_to_right"
android:clickable="true" android:clickable="true"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
android:padding="10dp"
android:src="@drawable/ic_chevron_left" android:src="@drawable/ic_chevron_left"
android:layout_toLeftOf="@id/nav_to_right"
android:tint="@color/text_desc" android:tint="@color/text_desc"
tools:ignore="UseAppTint" tools:ignore="UseAppTint"
android:padding="10dp" /> android:focusable="true" />
<ImageView <ImageView
android:id="@+id/nav_to_right" android:id="@+id/nav_to_right"
android:layout_width="50dp" android:layout_width="45dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_marginEnd="5dp"
android:clickable="true" android:clickable="true"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
android:padding="10dp"
android:src="@drawable/ic_chevron_right" android:src="@drawable/ic_chevron_right"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:tint="@color/text_desc" android:tint="@color/text_desc"
tools:ignore="UseAppTint" tools:ignore="UseAppTint"
android:padding="10dp" /> android:focusable="true" />
<TextView <TextView
android:id="@+id/nav_current" android:id="@+id/nav_current"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentLeft="true" android:layout_alignParentStart="true"
android:layout_marginLeft="20sp" android:layout_marginStart="15sp"
android:layout_toLeftOf="@id/nav_refresh" android:layout_marginTop="2sp"
android:layout_toStartOf="@id/nav_refresh"
android:fontFamily="@font/montserrat_medium" android:fontFamily="@font/montserrat_medium"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"
android:text="Timetable" android:text="Órarend"
android:textColor="@color/text" android:textColor="@color/text"
android:textSize="24sp" android:textSize="22sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
@ -131,8 +139,9 @@
android:text="A widget használatához, bejelentkezés szükséges." android:text="A widget használatához, bejelentkezés szükséges."
android:textColor="@color/black" android:textColor="@color/black"
android:paddingTop="10dp" android:paddingTop="10dp"
android:textSize="17dp" android:textSize="17sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/open_login" android:id="@+id/open_login"
@ -145,8 +154,9 @@
android:layout_margin="10dp" android:layout_margin="10dp"
android:textColor="@color/white" android:textColor="@color/white"
android:fontFamily="@font/montserrat_medium" android:fontFamily="@font/montserrat_medium"
android:textSize="16dp" android:textSize="16sp"
android:textStyle="bold"/> android:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout> </RelativeLayout>
@ -185,8 +195,9 @@
android:text="Órák a kezdőképernyőd kényelméből." android:text="Órák a kezdőképernyőd kényelméből."
android:textColor="@color/black" android:textColor="@color/black"
android:paddingTop="10dp" android:paddingTop="10dp"
android:textSize="16dp" android:textSize="16sp"
android:textStyle="bold" /> android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -197,7 +208,8 @@
android:textColor="@color/black" android:textColor="@color/black"
android:layout_marginTop="0dp" android:layout_marginTop="0dp"
android:layout_marginHorizontal="15dp" android:layout_marginHorizontal="15dp"
android:textSize="14dp" /> android:textSize="14sp"
tools:ignore="HardcodedText" />
<Button <Button
android:id="@+id/buy_premium" android:id="@+id/buy_premium"
@ -211,8 +223,9 @@
android:layout_margin="10dp" android:layout_margin="10dp"
android:textColor="#ff691A9B" android:textColor="#ff691A9B"
android:fontFamily="@font/montserrat_medium" android:fontFamily="@font/montserrat_medium"
android:textSize="16dp" android:textSize="16sp"
android:textStyle="bold"/> android:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout> </RelativeLayout>

View File

@ -27,7 +27,7 @@
<color name="yellow_light">#ffFFCC00</color> <color name="yellow_light">#ffFFCC00</color>
<color name="light_yellow_light">#40FFD60A</color> <color name="light_yellow_light">#40FFD60A</color>
<color name="green_light">#ff34C759</color> <color name="green_light">#ff34C759</color>
<color name="filc_light">#ff247665</color> <color name="filc_light">#ff3D7BF4</color>
<color name="teal_light">#ff5AC8FA</color> <color name="teal_light">#ff5AC8FA</color>
<color name="blue_light">#ff007AFF</color> <color name="blue_light">#ff007AFF</color>
<color name="indigo_light">#ff5856D6</color> <color name="indigo_light">#ff5856D6</color>
@ -49,7 +49,7 @@
<color name="yellow">#ffFFD60A</color> <color name="yellow">#ffFFD60A</color>
<color name="light_yellow">#40FFD60A</color> <color name="light_yellow">#40FFD60A</color>
<color name="green">#ff32D74B</color> <color name="green">#ff32D74B</color>
<color name="filc">#ff29826F</color> <color name="filc">#ff3D7BF4</color>
<color name="teal">#ff64D2FF</color> <color name="teal">#ff64D2FF</color>
<color name="blue">#ff0A84FF</color> <color name="blue">#ff0A84FF</color>
<color name="indigo">#ff5E5CE6</color> <color name="indigo">#ff5E5CE6</color>

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h> #include <dynamic_color/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h> #include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
@ -14,6 +15,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar = g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar); dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar = g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin");
flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar); flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color dynamic_color
file_selector_linux
flutter_acrylic flutter_acrylic
url_launcher_linux url_launcher_linux
) )

View File

@ -7,6 +7,7 @@ import Foundation
import connectivity_plus import connectivity_plus
import dynamic_color import dynamic_color
import file_selector_macos
import flutter_local_notifications import flutter_local_notifications
import macos_window_utils import macos_window_utils
import package_info_plus import package_info_plus
@ -18,6 +19,7 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin")) MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))

View File

@ -24,7 +24,10 @@ class TimetableController extends ChangeNotifier {
current(); current();
} }
static int getWeekId(Week week) => (week.start.difference(getSchoolYearStart()).inDays / DateTime.daysPerWeek).ceil(); static int getWeekId(Week week) =>
(week.start.difference(getSchoolYearStart()).inDays /
DateTime.daysPerWeek)
.ceil();
static DateTime getSchoolYearStart() { static DateTime getSchoolYearStart() {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
@ -48,8 +51,10 @@ class TimetableController extends ChangeNotifier {
} }
// Jump shortcuts // Jump shortcuts
Future<void> next(BuildContext context) => jump(Week.fromId(currentWeekId + 1), context: context); Future<void> next(BuildContext context) =>
Future<void> previous(BuildContext context) => jump(Week.fromId(currentWeekId - 1), context: context); jump(Week.fromId(currentWeekId + 1), context: context);
Future<void> previous(BuildContext context) =>
jump(Week.fromId(currentWeekId - 1), context: context);
void current() { void current() {
Week week = Week.current(); Week week = Week.current();
int id = getWeekId(week); int id = getWeekId(week);
@ -60,7 +65,11 @@ class TimetableController extends ChangeNotifier {
_setWeek(Week.fromId(id)); _setWeek(Week.fromId(id));
} }
Future<void> jump(Week week, {required BuildContext context, bool initial = false, bool skip = false, bool loader = true}) async { Future<void> jump(Week week,
{required BuildContext context,
bool initial = false,
bool skip = false,
bool loader = true}) async {
if (_setWeek(week)) return; if (_setWeek(week)) return;
loadType = LoadType.initial; loadType = LoadType.initial;
@ -81,7 +90,9 @@ class TimetableController extends ChangeNotifier {
notifyListeners(); notifyListeners();
try { try {
await _fetchWeek(week, context: context).timeout(const Duration(seconds: 5), onTimeout: (() => throw "timeout")); await _fetchWeek(week, context: context).timeout(
const Duration(seconds: 5),
onTimeout: (() => throw "timeout"));
loadType = LoadType.online; loadType = LoadType.online;
} catch (error, stack) { } catch (error, stack) {
print("ERROR: TimetableController.jump: $error\n$stack"); print("ERROR: TimetableController.jump: $error\n$stack");
@ -95,7 +106,9 @@ class TimetableController extends ChangeNotifier {
if (week != currentWeek) return; if (week != currentWeek) return;
// Jump to next week on weekends // Jump to next week on weekends
if (skip && (days?.length ?? 0) > 0 && days!.last.last.end.isBefore(DateTime.now())) return next(context); if (skip &&
(days?.length ?? 0) > 0 &&
days!.last.last.end.isBefore(DateTime.now())) return next(context);
notifyListeners(); notifyListeners();
} }
@ -106,7 +119,8 @@ class TimetableController extends ChangeNotifier {
if (id < 0) return true; // Min 1. if (id < 0) return true; // Min 1.
// Set week start to Sept. 1 of first week // Set week start to Sept. 1 of first week
if (!_differentDate(week.start, Week.fromId(0).start)) week.start = TimetableController.getSchoolYearStart(); if (!_differentDate(week.start, Week.fromId(0).start))
week.start = TimetableController.getSchoolYearStart();
currentWeek = week; currentWeek = week;
previousWeekId = currentWeekId; previousWeekId = currentWeekId;
@ -124,16 +138,17 @@ class TimetableController extends ChangeNotifier {
List<List<Lesson>> _sortDays(Week week, {required BuildContext context}) { List<List<Lesson>> _sortDays(Week week, {required BuildContext context}) {
List<List<Lesson>> days = []; List<List<Lesson>> days = [];
final timetableProvider = context.read<TimetableProvider>();
try { try {
final timetableProvider = context.read<TimetableProvider>();
List<Lesson> lessons = timetableProvider.getWeek(week) ?? []; List<Lesson> lessons = timetableProvider.getWeek(week) ?? [];
if (lessons.isNotEmpty) { if (lessons.isNotEmpty) {
days.add([]); days.add([]);
lessons.sort((a, b) => a.date.compareTo(b.date)); lessons.sort((a, b) => a.date.compareTo(b.date));
for (var lesson in lessons) { for (var lesson in lessons) {
if (days.last.isNotEmpty && _differentDate(lesson.date, days.last.last.date)) days.add([]); if (days.last.isNotEmpty &&
_differentDate(lesson.date, days.last.last.date)) days.add([]);
days.last.add(lesson); days.last.add(lesson);
} }
@ -152,7 +167,8 @@ class TimetableController extends ChangeNotifier {
if (lessonIndexes.isNotEmpty) { if (lessonIndexes.isNotEmpty) {
// Fill missing indexes with empty spaces // Fill missing indexes with empty spaces
for (var i in List<int>.generate(maxIndex - minIndex + 1, (int i) => minIndex + i)) { for (var i in List<int>.generate(
maxIndex - minIndex + 1, (int i) => minIndex + i)) {
List<Lesson> indexLessons = _getLessonsByIndex(_day, i); List<Lesson> indexLessons = _getLessonsByIndex(_day, i);
// Empty lesson // Empty lesson
@ -160,8 +176,13 @@ class TimetableController extends ChangeNotifier {
// Get start date by previous lesson // Get start date by previous lesson
List<Lesson> prevLesson = _getLessonsByIndex(day, i - 1); List<Lesson> prevLesson = _getLessonsByIndex(day, i - 1);
try { try {
DateTime? startDate = prevLesson.last.start.add(const Duration(seconds: 1)); DateTime startDate =
indexLessons.add(Lesson.fromJson({'isEmpty': true, 'Oraszam': i, 'KezdetIdopont': startDate.toIso8601String()})); prevLesson.last.start.add(const Duration(seconds: 1));
indexLessons.add(Lesson.fromJson({
'isEmpty': true,
'Oraszam': i,
'KezdetIdopont': startDate.toIso8601String()
}));
// ignore: empty_catches // ignore: empty_catches
} catch (e) {} } catch (e) {}
} }
@ -171,7 +192,8 @@ class TimetableController extends ChangeNotifier {
} }
// Additional lessons // Additional lessons
day.addAll(_day.where((l) => int.tryParse(l.lessonIndex) == null && l.subject.id != '')); day.addAll(_day.where((l) =>
int.tryParse(l.lessonIndex) == null && l.subject.id != ''));
day.sort((a, b) => a.start.compareTo(b.start)); day.sort((a, b) => a.start.compareTo(b.start));
@ -213,5 +235,6 @@ class TimetableController extends ChangeNotifier {
return indexes; return indexes;
} }
bool _differentDate(DateTime a, DateTime b) => !(a.year == b.year && a.month == b.month && a.day == b.day); bool _differentDate(DateTime a, DateTime b) =>
!(a.year == b.year && a.month == b.month && a.day == b.day);
} }