diff --git a/.gitignore b/.gitignore index ddfc58b..2e80ede 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # See https://www.dartlang.org/guides/libraries/private-files +.gitignore + termek.txt .DS_Store filc3.properties @@ -25,9 +27,6 @@ doc/api/ *.js.map *.txt -filcnaplo/linux/flutter/generated_plugin_registrant.cc -filcnaplo/linux/flutter/generated_plugin_registrant.h -filcnaplo/linux/flutter/generated_plugins.cmake filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift filcnaplo/windows/flutter/ephemeral/.plugin_symlinks/connectivity_plus filcnaplo/windows/flutter/ephemeral/.plugin_symlinks/dynamic_color @@ -43,10 +42,9 @@ filcnaplo/windows/flutter/generated_plugins.cmake filcnaplo/linux/flutter/generated_plugin_registrant.cc filcnaplo/linux/flutter/generated_plugin_registrant.h filcnaplo/linux/flutter/generated_plugins.cmake -filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift -filcnaplo/linux/flutter/generated_plugin_registrant.cc -filcnaplo/linux/flutter/generated_plugin_registrant.h -filcnaplo/linux/flutter/generated_plugins.cmake -filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift +filcnaplo/macos/Flutter/* +filcnaplo/ios/Podfile.lock .vscode/ - \ No newline at end of file +key.properties + +.flutter-plugins* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff618bc..987426b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,39 +1,36 @@ -# Hozzájárulási útmutató +# Contribution guide Köszönjük, ha programozással segíted a munkánkat! -A folytatáshoz szükséged lesz egy Linuxot vagy Windowst futtató számítógépre, minimális programozási tapasztalatra és egy kis angoltudásra. -Segít, ha nem csak kicsit tudsz programozni, és ha ismered a Gitet és a GitHubot ;) +A folytatáshoz szükséged lesz egy Linux-ot vagy Windows-t futtató számítógépre, minimális programozási tapasztalatra és egy kis angoltudásra. +Segít, ha már gyakorlottabb vagy a programozásban, és ha ismered a [Git](https://git-scm.com/) és a [GitHub](https://github.com/) működését. ;) ## Miben segítsek? -Kérünk, **olyan dologgal járulj hozzá** a reFilchez, ami valószínűleg **sok embernek hasznos lesz** majd. Szeretnénk egy minél teljeskörűbb iskolai asszisztenst létrehozni, de az iskolaspecifikus, vagy külön neked hasznos funkciók helye inkább legyen a saját forkod. +Kérünk, **olyan dologgal járulj hozzá** a **reFilc**hez, ami valószínűleg **sok embernek hasznos lehet**. Szeretnénk egy minél teljeskörűbb iskolai asszisztenst létrehozni, de az iskolaspecifikus, vagy külön neked hasznos funkciók helye inkább legyen a saját Fork-od. -Fontos, hogy **mielőtt egy nagy volumenű projektbe belekezdesz, futtasd meg ötletedet a [Discord szerverünkön](https://dc.refilc.hu/),** ahol még azelőtt tudunk tanácsot adni, mielőtt sok-sok órát beleöltél volna egy esetleg felesleges dologba. +Fontos, hogy **mielőtt egy nagyobb méretű projektbe belekezdenél, futtasd meg ötletedet a [Discord szerverünkön](https://dc.refilc.hu/)**, ahol még azelőtt tudunk tanácsot adni, hogy sok-sok órát beleöltél volna egy esetleg felesleges dologba. -A legjobban annak örülünk, ha az [Issues](https://github.com/refilc/naplo/issues) oldalról szemezgetsz, **ha lehet, a [help wanted taggel megjelöltekkel kezdd](https://github.com/refilc/naplo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22),** vagy ha új vagy a Flutterhez, ajánljuk figyelmedbe [ezeket a viszonylag könnyen javítható hibákat](https://github.com/refilc/naplo/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) (ha épp van ilyen). +A legjobban annak örülünk, ha az [Issues](https://github.com/refilc/naplo/issues) oldalról szemezgetsz. Ha még új vagy a Flutterben, ajánljuk figyelmedbe ezeket a [viszonylag könnyen javítható hibákat](https://github.com/refilc/naplo/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22), ha éppen van ilyen. ## Hogyan segítsek? +Nem ígérhetünk itt sem programozás-, sem Git-kurzust, de a projektspecifikus dolgokat leírjuk, és segítünk a Flutter telepítésében. -Nem ígérhetünk itt sem programozás-, sem git-kurzust, de a projektspecifikus dolgokat leírjuk, és segítünk a Flutter feltelepítésében. +A **reFilc** a Google által pár éve létrehozott **[Flutter](https://flutter.dev/)** keretrendszert használja, aminek nyelve a **[Dart](https://dart.dev/)**. Ha ismered a C#, Java, C++, vagy egyéb hasonló programnyelvek működését, **nem fog nagy gondot okozni a használata.** A felhasználói felület létrehozásában az is segíthet, ha foglalkoztál már korábban weboldalakkal vagy alkalmazásfejlesztéssel. +Ha még nem használtad a Flutter-t, mindenképp böngészd át a [YouTube csatornájukat](https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw). +Kód vagy UI teszteléséhez Flutter telepítése nélkül is használhatod a [DartPad](https://dartpad.dev/)-et. -A reFilc a Google által pár éve létrehozott **[Fluttert](https://flutter.dev/)** használja, aminek nyelve a **[Dart](https://dart.dev/)**. Ha ismered a C#-ot, Javát, C++t, vagy egyéb hasonló nyelvet, **nem fog gondot okozni a használata.** A felhasználói felület létrehozásában az is segíthet, ha foglalkoztál már korábban weboldalakkal. -Ha még nem használtál Fluttert, mindenképp böngészd át a [YouTube csatornájukat](https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw). -Könnyen tudsz kódot, vagy akár UI-t is tesztelni a [DartPad](https://dartpad.dev/) oldalon. +#### [Segítség a Flutter telepítéséhez](https://docs.flutter.dev/get-started/install) +**Használd a Flutter stable verzióját!** Írd be a terminálba: `flutter channel stable` -#### [Segítség a Flutter telepítéséhez és a forráskód futtatásához](https://docs.flutter.dev/get-started/install) -Fontos: **Legyél a flutter beta verzióján!** Írd be: `flutter channel beta` +Ha nem értessz a Git-hez vagy a GitHub-hoz, ajánljuk figyelmedbe [ezt a cikket](https://medium.com/envienta-magyarorsz%C3%A1g/git-%C3%A9s-github-gyorstalpal%C3%B3-f2d78a732deb), viszont arra kérünk, hogy a használatukat ne a **reFilc**en próbáld ki először. Hozz létre egy saját Repo-t és abban tesztelgess. Ha már nagyjából kitapasztaltad, várjuk hozzájárulásodat. - - -Ha nem értesz a Githez, ajánljuk figyelmedbe [ezt a cikket](https://medium.com/envienta-magyarorsz%C3%A1g/git-%C3%A9s-github-gyorstalpal%C3%B3-f2d78a732deb). Viszont arra kérünk, a Git használatát ne a reFilcen próbáld ki először, hozz létre előbb egy saját Repót, és abba tesztelgess. Ha már nagyjából kitapasztaltad, várjuk hozzájárulásodat. - -Készíts egy forkot a saját fiókod alá. -A reFilc legfrissebb, épp fejlesztés alatt álló verzióját a [master branch](https://github.com/refilc/naplo/tree/master)-en találod, kérjük ide commitolj, és ide célozd a forkodból a Pull Requested. Írd le benne, mit változtattál, és ha lehet, csatolj képernyőképet is. -Minél gyakrabban készíts minél részletesebben elnevezett commitokat, hogy el tudjunk tájékozódni az általad beküldött kódon. +Készíts egy Fork-ot a saját GitHub fiókod alá. +A **reFilc** legfrissebb, **épp fejlesztés alatt álló verzióját a [master branch](https://github.com/refilc/naplo/tree/master)-en találod**. Kérjük ide Commit-olj és ide célozd a Fork-odból a Pull Request-edet. Írd le benne, hogy mit változtattál és ha lehet, csatolj képernyőképet is. +Minél gyakrabban készíts minél részletesebben elnevezett Commit-okat, hogy mások is el tudjanak igazodni az általad beküldött kódban. --- -Az általad fejlesztett funkciók mellé a changelogban odakerül GitHub felhasználóneved. -Ha jelentős és rendszeres hozzájáruló vagy, Discordon megkapod a `DEV` rangot. +Az általad fejlesztett funkciók mellé a Changelog-ba odakerül a GitHub felhasználóneved. +Ha jelentős és rendszeres hozzájáruló vagy, Discord-on megkaphatod a `DEV` rangot. -Ha bárhol elakadtál, keress minket Discordon. -Jó fejlesztést kívánunk! +Ha bárhol elakadtál vagy kérdésed van, keress bátran Discordon! +**Jó fejlesztést kívánunk!** diff --git a/README.md b/README.md index e9a3541..c7e5ae9 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ #### Nem hivatalos e-napló alkalmazás az eKRÉTA rendszerhez - tanulóktól, tanulóknak. -[![Downloads](https://img.shields.io/github/downloads-pre/refilc/naplo/total?color=%23&label=Downloads&logo=github&sort=semver)](https://github.com/refilc/naplo/releases)   [![discord](https://img.shields.io/discord/1111649116020285532?label=Discord)](http://dc.refilc.hu) +[![Downloads](https://img.shields.io/github/downloads-pre/refilc/naplo/total?&logo=github&label=Downloads)](https://github.com/refilc/naplo/releases)   [![Discord](https://img.shields.io/discord/1111649116020285532?logo=discord&label=Discord)](https://dc.refilc.hu) ## Setup ### Clone the project ```sh -git clone --recursive https://github.com/refilc/naplo +git clone https://github.com/refilc/naplo cd naplo ``` @@ -29,11 +29,13 @@ flutter run ### Contribution +**Nézd meg a [Contribution guide](CONTRIBUTING.md)-ot!** + Az összes (ugyan azon verzióhoz tartozó) contribution meg fog jelenni a release-nél. Kérjük, írd le a Discord nevedet a Description-be, hogy adhassunk rangot. ------- -# Kudo +# Developers **annon:** a Filc napló készítője (ez az app a Filcen alapul) diff --git a/filcnaplo/.gitignore b/filcnaplo/.gitignore index 8906afc..7900af4 100644 --- a/filcnaplo/.gitignore +++ b/filcnaplo/.gitignore @@ -44,3 +44,4 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release +key.properties diff --git a/filcnaplo/.metadata b/filcnaplo/.metadata index ebe4e24..bd1207f 100644 --- a/filcnaplo/.metadata +++ b/filcnaplo/.metadata @@ -1,30 +1,30 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled. - -version: - revision: 3c0bee85b8e43b860877922bdc411a7333db4d32 - channel: beta - -project_type: app - -# Tracks metadata for the flutter migrate command -migration: - platforms: - - platform: root - create_revision: 3c0bee85b8e43b860877922bdc411a7333db4d32 - base_revision: 3c0bee85b8e43b860877922bdc411a7333db4d32 - - platform: macos - create_revision: 3c0bee85b8e43b860877922bdc411a7333db4d32 - base_revision: 3c0bee85b8e43b860877922bdc411a7333db4d32 - - # User provided section - - # List of Local paths (relative to this file) that should be - # ignored by the migrate tool. - # - # Files that are not part of the templates will be ignored by default. - unmanaged_files: - - 'lib/main.dart' - - 'ios/Runner.xcodeproj/project.pbxproj' +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: web + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/filcnaplo/android/app/src/main/AndroidManifest.xml b/filcnaplo/android/app/src/main/AndroidManifest.xml index 2877685..14d49f3 100644 --- a/filcnaplo/android/app/src/main/AndroidManifest.xml +++ b/filcnaplo/android/app/src/main/AndroidManifest.xml @@ -2,12 +2,14 @@ xmlns:tools="http://schemas.android.com/tools" package="hu.refilc.naplo"> - + @@ -18,16 +20,26 @@ - + + android:host="api.refilcapp.hu" + android:pathPrefix="/v1/auth/callback" /> + + + + + + + - @@ -43,7 +55,7 @@ android:resource="@xml/home_widget_test_info" /> - + + + diff --git a/filcnaplo/android/app/src/main/java/hu/filc/naplo/database b/filcnaplo/android/app/src/main/java/hu/filc/naplo/database deleted file mode 120000 index a298c9a..0000000 --- a/filcnaplo/android/app/src/main/java/hu/filc/naplo/database +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../filcnaplo_premium/android/database \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/java/hu/filc/naplo/utils b/filcnaplo/android/app/src/main/java/hu/filc/naplo/utils deleted file mode 120000 index 0a05323..0000000 --- a/filcnaplo/android/app/src/main/java/hu/filc/naplo/utils +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../filcnaplo_premium/android/utils \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/java/hu/filc/naplo/widget_timetable b/filcnaplo/android/app/src/main/java/hu/filc/naplo/widget_timetable deleted file mode 120000 index 0314e40..0000000 --- a/filcnaplo/android/app/src/main/java/hu/filc/naplo/widget_timetable +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../../filcnaplo_premium/android/widget_timetable \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/java/hu/filc/naplo/MainActivity.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/MainActivity.java similarity index 69% rename from filcnaplo/android/app/src/main/java/hu/filc/naplo/MainActivity.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/MainActivity.java index 2fb810e..ff22fb7 100644 --- a/filcnaplo/android/app/src/main/java/hu/filc/naplo/MainActivity.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/MainActivity.java @@ -1,9 +1,7 @@ -package hu.refilc.naplo; - -import io.flutter.embedding.android.FlutterActivity; - -import io.flutter.embedding.engine.FlutterEngine; - -public class MainActivity extends FlutterActivity { - -} +package hu.refilc.naplo; + +import io.flutter.embedding.android.FlutterActivity; + +public class MainActivity extends FlutterActivity { + +} diff --git a/filcnaplo_premium/android/database/DBManager.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/DBManager.java similarity index 97% rename from filcnaplo_premium/android/database/DBManager.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/DBManager.java index 996ed4f..b39409d 100644 --- a/filcnaplo_premium/android/database/DBManager.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/DBManager.java @@ -1,119 +1,119 @@ -package hu.refilc.naplo.database; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; - -import java.sql.SQLException; - -import hu.refilc.naplo.database.SQLiteHelper; - -public class DBManager { - private Context context; - private SQLiteDatabase database; - private SQLiteHelper dbHelper; - - public DBManager(Context c) { - this.context = c; - } - - public DBManager open() throws SQLException { - this.dbHelper = new SQLiteHelper(this.context); - this.database = this.dbHelper.getWritableDatabase(); - return this; - } - - public void close() { - this.dbHelper.close(); - } - - 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); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchTimetable() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER_DATA, new String[]{SQLiteHelper.TIMETABLE}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchLastUser() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LAST_ACCOUNT_ID}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchTheme() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.THEME, SQLiteHelper.ACCENT_COLOR}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchPremiumToken() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_TOKEN}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchPremiumScopes() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_SCOPES}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public Cursor fetchLocale() { - Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LOCALE}, null, null, null, null, null); - if (cursor != null) { - cursor.moveToFirst(); - } - return cursor; - } - - public void deleteWidget(int _id) { - this.database.delete(SQLiteHelper.TABLE_NAME_WIDGETS, "_id=" + _id, null); - } - - /*public void changeSettings(int _id, Map map) { - ContentValues con = new ContentValues(); - for(Map.Entry e: map.entrySet()){ - con.put(e.getKey(), e.getValue()); - } - this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, "_id = " + _id, null); - } - public void insertSettings(int _id, Map map) { - ContentValues con = new ContentValues(); - for(Map.Entry e: map.entrySet()){ - con.put(e.getKey(), e.getValue()); - //Log.d("Settings added", e.getKey() + " - " + e.getValue()); - } - this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); - }*/ - - public void insertSelDay(int _id, int day_sel) { - ContentValues con = new ContentValues(); - con.put(SQLiteHelper._ID, _id); - con.put(SQLiteHelper.DAY_SEL, day_sel); - this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); - } - - public int update(int _id, int day_sel) { - ContentValues con = new ContentValues(); - con.put(SQLiteHelper.DAY_SEL, day_sel); - return this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, SQLiteHelper._ID + " = " + _id, null); - } +package hu.refilc.naplo.database; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.sql.SQLException; + +import hu.refilc.naplo.database.SQLiteHelper; + +public class DBManager { + private Context context; + private SQLiteDatabase database; + private SQLiteHelper dbHelper; + + public DBManager(Context c) { + this.context = c; + } + + public DBManager open() throws SQLException { + this.dbHelper = new SQLiteHelper(this.context); + this.database = this.dbHelper.getWritableDatabase(); + return this; + } + + public void close() { + this.dbHelper.close(); + } + + 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); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchTimetable() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER_DATA, new String[]{SQLiteHelper.TIMETABLE}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchLastUser() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LAST_ACCOUNT_ID}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchTheme() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.THEME, SQLiteHelper.ACCENT_COLOR}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchPremiumToken() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_TOKEN}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchPremiumScopes() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.PREMIUM_SCOPES}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public Cursor fetchLocale() { + Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_SETTINGS, new String[]{SQLiteHelper.LOCALE}, null, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + } + return cursor; + } + + public void deleteWidget(int _id) { + this.database.delete(SQLiteHelper.TABLE_NAME_WIDGETS, "_id=" + _id, null); + } + + /*public void changeSettings(int _id, Map map) { + ContentValues con = new ContentValues(); + for(Map.Entry e: map.entrySet()){ + con.put(e.getKey(), e.getValue()); + } + this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, "_id = " + _id, null); + } + public void insertSettings(int _id, Map map) { + ContentValues con = new ContentValues(); + for(Map.Entry e: map.entrySet()){ + con.put(e.getKey(), e.getValue()); + //Log.d("Settings added", e.getKey() + " - " + e.getValue()); + } + this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); + }*/ + + public void insertSelDay(int _id, int day_sel) { + ContentValues con = new ContentValues(); + con.put(SQLiteHelper._ID, _id); + con.put(SQLiteHelper.DAY_SEL, day_sel); + this.database.insert(SQLiteHelper.TABLE_NAME_WIDGETS, null, con); + } + + public int update(int _id, int day_sel) { + ContentValues con = new ContentValues(); + con.put(SQLiteHelper.DAY_SEL, day_sel); + return this.database.update(SQLiteHelper.TABLE_NAME_WIDGETS, con, SQLiteHelper._ID + " = " + _id, null); + } } \ No newline at end of file diff --git a/filcnaplo_premium/android/database/SQLiteHelper.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/SQLiteHelper.java similarity index 97% rename from filcnaplo_premium/android/database/SQLiteHelper.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/SQLiteHelper.java index 11b22fb..5944408 100644 --- a/filcnaplo_premium/android/database/SQLiteHelper.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/database/SQLiteHelper.java @@ -1,36 +1,36 @@ -package hu.refilc.naplo.database; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.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 DB_NAME = "app.db"; - private static final int DB_VERSION = 1; - public static final String _ID = "_id"; - public static final String DAY_SEL = "day_sel"; - public static final String TIMETABLE = "timetable"; - public static final String LAST_ACCOUNT_ID = "last_account_id"; - public static final String THEME = "theme"; - public static final String PREMIUM_TOKEN = "premium_token"; - public static final String PREMIUM_SCOPES = "premium_scopes"; - public static final String LOCALE = "language"; - public static final String ACCENT_COLOR = "accent_color"; - public static final String TABLE_NAME_WIDGETS = "widgets"; - public static final String TABLE_NAME_USER_DATA = "user_data"; - public static final String TABLE_NAME_SETTINGS = "settings"; - - public SQLiteHelper(Context context) { - super(context, DB_NAME, null, 7); - } - - public void onCreate(SQLiteDatabase db) { - db.execSQL(CREATE_TABLE_WIDGET); - } - - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - db.execSQL("DROP TABLE IF EXISTS widgets"); - onCreate(db); - } +package hu.refilc.naplo.database; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.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 DB_NAME = "app.db"; + private static final int DB_VERSION = 1; + public static final String _ID = "_id"; + public static final String DAY_SEL = "day_sel"; + public static final String TIMETABLE = "timetable"; + public static final String LAST_ACCOUNT_ID = "last_account_id"; + public static final String THEME = "theme"; + public static final String PREMIUM_TOKEN = "premium_token"; + public static final String PREMIUM_SCOPES = "premium_scopes"; + public static final String LOCALE = "language"; + public static final String ACCENT_COLOR = "accent_color"; + public static final String TABLE_NAME_WIDGETS = "widgets"; + public static final String TABLE_NAME_USER_DATA = "user_data"; + public static final String TABLE_NAME_SETTINGS = "settings"; + + public SQLiteHelper(Context context) { + super(context, DB_NAME, null, 7); + } + + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_TABLE_WIDGET); + } + + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS widgets"); + onCreate(db); + } } \ No newline at end of file diff --git a/filcnaplo_premium/android/utils/Utils.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Utils.java similarity index 96% rename from filcnaplo_premium/android/utils/Utils.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Utils.java index 51f635b..30f2a62 100644 --- a/filcnaplo_premium/android/utils/Utils.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Utils.java @@ -1,36 +1,36 @@ -package hu.refilc.naplo.utils; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - -import java.util.Calendar; -import java.util.Date; - -public class Utils { - public static boolean hasNetwork(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getActiveNetworkInfo(); - if (netInfo != null && netInfo.isConnectedOrConnecting()) { - return true; - } - return false; - } - - public static Date getWeekStartDate() { - Calendar calendar = Calendar.getInstance(); - while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { - calendar.add(Calendar.DATE, -1); - } - return calendar.getTime(); - } - - public static Date getWeekEndDate() { - Calendar calendar = Calendar.getInstance(); - while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { - calendar.add(Calendar.DATE, 1); - } - calendar.add(Calendar.DATE, -1); - return calendar.getTime(); - } -} +package hu.refilc.naplo.utils; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; + +import java.util.Calendar; +import java.util.Date; + +public class Utils { + public static boolean hasNetwork(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo netInfo = cm.getActiveNetworkInfo(); + if (netInfo != null && netInfo.isConnectedOrConnecting()) { + return true; + } + return false; + } + + public static Date getWeekStartDate() { + Calendar calendar = Calendar.getInstance(); + while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { + calendar.add(Calendar.DATE, -1); + } + return calendar.getTime(); + } + + public static Date getWeekEndDate() { + Calendar calendar = Calendar.getInstance(); + while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { + calendar.add(Calendar.DATE, 1); + } + calendar.add(Calendar.DATE, -1); + return calendar.getTime(); + } +} \ No newline at end of file diff --git a/filcnaplo_premium/android/utils/Week.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Week.java similarity index 96% rename from filcnaplo_premium/android/utils/Week.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Week.java index e823c18..9f62c3e 100644 --- a/filcnaplo_premium/android/utils/Week.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/utils/Week.java @@ -1,65 +1,65 @@ -package hu.refilc.naplo.utils; - -import java.time.DayOfWeek; -import java.time.Duration; -import java.time.LocalDate; - -public class Week { - private final LocalDate start; - private final LocalDate end; - - private Week(LocalDate start, LocalDate end) { - this.start = start; - this.end = end; - } - - public static Week current() { - return fromDate(LocalDate.now()); - } - - public static Week fromId(int id) { - LocalDate _now = getYearStart().plusDays(id * 7L); - return new Week(_now.minusDays(_now.getDayOfWeek().getValue() - 1), _now.plusDays(7 - _now.getDayOfWeek().getValue())); - } - - public static Week fromDate(LocalDate date) { - - return new Week(date.minusDays(date.getDayOfWeek().getValue() - 1), date.plusDays(7 - date.getDayOfWeek().getValue())); - } - - public Week next() { - return Week.fromDate(start.plusDays(8)); - } - - public int id() { - return (int) Math.ceil(Duration.between(getYearStart().atStartOfDay(), start.atStartOfDay()).toDays() / 7f); - } - - private static LocalDate getYearStart() { - LocalDate now = LocalDate.now(); - LocalDate start = getYearStart(now.getYear()); - return start.isBefore(now) ? start : getYearStart(now.getYear() -1); - } - - private static LocalDate getYearStart(int year) { - LocalDate time = LocalDate.of(year, 9, 1); - if (time.getDayOfWeek() == DayOfWeek.SATURDAY) - return time.plusDays(2); - else if (time.getDayOfWeek() == DayOfWeek.SUNDAY) - return time.plusDays(1); - return time; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Week week = (Week) o; - return this.id() == week.id(); - } - - @Override - public int hashCode() { - return id(); - } +package hu.refilc.naplo.utils; + +import java.time.DayOfWeek; +import java.time.Duration; +import java.time.LocalDate; + +public class Week { + private final LocalDate start; + private final LocalDate end; + + private Week(LocalDate start, LocalDate end) { + this.start = start; + this.end = end; + } + + public static Week current() { + return fromDate(LocalDate.now()); + } + + public static Week fromId(int id) { + LocalDate _now = getYearStart().plusDays(id * 7L); + return new Week(_now.minusDays(_now.getDayOfWeek().getValue() - 1), _now.plusDays(7 - _now.getDayOfWeek().getValue())); + } + + public static Week fromDate(LocalDate date) { + + return new Week(date.minusDays(date.getDayOfWeek().getValue() - 1), date.plusDays(7 - date.getDayOfWeek().getValue())); + } + + public Week next() { + return Week.fromDate(start.plusDays(8)); + } + + public int id() { + return (int) Math.ceil(Duration.between(getYearStart().atStartOfDay(), start.atStartOfDay()).toDays() / 7f); + } + + private static LocalDate getYearStart() { + LocalDate now = LocalDate.now(); + LocalDate start = getYearStart(now.getYear()); + return start.isBefore(now) ? start : getYearStart(now.getYear() -1); + } + + private static LocalDate getYearStart(int year) { + LocalDate time = LocalDate.of(year, 9, 1); + if (time.getDayOfWeek() == DayOfWeek.SATURDAY) + return time.plusDays(2); + else if (time.getDayOfWeek() == DayOfWeek.SUNDAY) + return time.plusDays(1); + return time; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Week week = (Week) o; + return this.id() == week.id(); + } + + @Override + public int hashCode() { + return id(); + } } \ No newline at end of file diff --git a/filcnaplo_premium/android/widget_timetable/WidgetTimetable.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetable.java similarity index 97% rename from filcnaplo_premium/android/widget_timetable/WidgetTimetable.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetable.java index 6336edf..80413c3 100644 --- a/filcnaplo_premium/android/widget_timetable/WidgetTimetable.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetable.java @@ -1,397 +1,397 @@ -package hu.refilc.naplo.widget_timetable; - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProvider; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.RemoteViews; -import android.widget.Toast; - -import org.joda.time.DateTime; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.time.DayOfWeek; -import java.time.format.TextStyle; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Locale; - -import hu.refilc.naplo.database.DBManager; -import hu.refilc.naplo.MainActivity; -import hu.refilc.naplo.R; - -import hu.refilc.naplo.utils.Week; - -import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; - -import es.antonborri.home_widget.HomeWidgetBackgroundIntent; -import es.antonborri.home_widget.HomeWidgetLaunchIntent; -import es.antonborri.home_widget.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_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_REFRESH = "list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH"; - private static final String ACTION_WIDGET_CLICK_BUY_PREMIUM = "list_widget.ACTION_WIDGET_CLICK_BUY_PREMIUM"; - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, SharedPreferences widgetData) { - for (int i = 0; i < appWidgetIds.length; i++) { - RemoteViews views = generateView(context, appWidgetIds[i]); - - if(premiumEnabled(context) && userLoggedIn(context)) { - int rday = selectDay(context, appWidgetIds[i], 0, true); - views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); - } - - pushUpdate(context, views, appWidgetIds[i]); - } - } - - public static void pushUpdate(Context context, RemoteViews remoteViews, int appWidgetSingleId) { - AppWidgetManager manager = AppWidgetManager.getInstance(context); - - manager.updateAppWidget(appWidgetSingleId, remoteViews); - manager.notifyAppWidgetViewDataChanged(appWidgetSingleId, R.id.widget_list); - } - - public static RemoteViews generateView(Context context, int appId) { - Intent serviceIntent = new Intent(context, WidgetTimetableService.class); - serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId); - serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); - - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_timetable); - - views.setViewVisibility(R.id.need_premium, View.GONE); - views.setViewVisibility(R.id.need_login, View.GONE); - views.setViewVisibility(R.id.tt_grid_cont, View.GONE); - - if(!userLoggedIn(context)) { - views.setViewVisibility(R.id.need_login, View.VISIBLE); - views.setOnClickPendingIntent(R.id.open_login, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); - } else if(premiumEnabled(context)) { - 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_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_refresh, makePending(context, ACTION_WIDGET_CLICK_NAV_REFRESH, appId)); - views.setRemoteAdapter(R.id.widget_list, serviceIntent); - views.setEmptyView(R.id.widget_list, R.id.empty_view); - } else { - views.setViewVisibility(R.id.need_premium, View.VISIBLE); - views.setOnClickPendingIntent(R.id.buy_premium, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); - } - - return views; - } - - static PendingIntent makePending(Context context, String action, int appWidgetId) { - Intent activebtnnext = new Intent(context, WidgetTimetable.class); - activebtnnext.setAction(action); - activebtnnext.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - return PendingIntent.getBroadcast(context, appWidgetId, activebtnnext , PendingIntent.FLAG_IMMUTABLE); - } - - @Override - public void onReceive(Context context, Intent intent) { - super.onReceive(context, intent); - - if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { - int appId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); - RemoteViews views = generateView(context, appId); - - try { - if(premiumEnabled(context) && userLoggedIn(context)) { - if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_LEFT)) { - int rday = selectDay(context, appId, -1, false); - views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); - - pushUpdate(context, views, appId); - } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_RIGHT)) { - int rday = selectDay(context, appId, 1, false); - views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); - - pushUpdate(context, views, appId); - } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_TODAY)) { - int rday = getToday(context); - setSelectedDay(context, appId, rday); - - views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); - - pushUpdate(context, views, appId); - } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_REFRESH)) { - PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("timetable://refresh")); - pendingIntent.send(); - } else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_DELETED")) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - dbManager.deleteWidget(appId); - dbManager.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - if(intent.getAction().equals(ACTION_WIDGET_CLICK_BUY_PREMIUM)) { - PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("settings://premium")); - pendingIntent.send(); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - public static String convertDayOfWeek(Context context, int rday) { - - /*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 = "Unknown"; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Locale loc = getLocale(context); - - if (rday == -1) - return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, loc); - - dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, loc); - } - - return dayOfWeek.substring(0, 1).toUpperCase() + dayOfWeek.substring(1).toLowerCase(); - } - - public static void setSelectedDay(Context context, int wid, int day) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - dbManager.update(wid, day); - dbManager.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static int getToday(Context context) { - int rday = new DateTime().getDayOfWeek() - 1; - List s = genJsonDays(context); - - try { - if(checkIsAfter(s, rday)) rday += 1; - } catch (Exception e) { - e.printStackTrace(); - } - return retDay(rday, s.size()); - } - - public static int selectDay(Context context, int wid, int add, Boolean afterSubjects) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - Cursor cursor = dbManager.fetchWidget(wid); - - List s = genJsonDays(context); - int retday = new DateTime().getDayOfWeek() - 1; - - if(cursor.getCount() != 0) retday = retDay(cursor.getInt(1) + add, s.size()); - - if(afterSubjects) if(checkIsAfter(s, retday)) retday += 1; - retday = retDay(retday, s.size()); - - if(cursor.getCount() == 0) dbManager.insertSelDay(wid, retday); - else dbManager.update(wid, retday); - - dbManager.close(); - - return retday; - } catch (Exception e) { - e.printStackTrace(); - } - - return 0; - } - - public static Boolean checkIsAfter(List s, int retday) throws Exception { - retday = retDay(retday, s.size()); - - String vegIdopont = s.get(retday).getJSONObject(s.get(retday).length() - 1).getString("VegIdopont"); - - return new DateTime().isAfter(new DateTime(vegIdopont)); - } - - public static int retDay(int retday, int size) { - if (retday < 0) retday = size - 1; - else if (retday > size - 1) retday = 0; - - return retday; - } - - public static List genJsonDays(Context context) { - List gen_days = new ArrayList<>(); - - DBManager dbManager = new DBManager(context.getApplicationContext()); - try { - dbManager.open(); - Cursor ct = dbManager.fetchTimetable(); - dbManager.close(); - - if(ct.getCount() == 0) { - return gen_days; - } - - JSONObject fecthtt = new JSONObject(ct.getString(0)); - - JSONArray dayArray = new JSONArray(); - String currday = ""; - - String currweek = String.valueOf(Week.current().id()); - - JSONArray week = fecthtt.getJSONArray(currweek); - - for (int i=0; i < week.length(); i++) - { - try { - if(i == 0) currday = week.getJSONObject(0).getString("Datum"); - JSONObject oraObj = week.getJSONObject(i); - - if(!currday.equals(oraObj.getString("Datum"))) { - gen_days.add(dayArray); - currday = week.getJSONObject(i).getString("Datum"); - dayArray = new JSONArray(); - } - - dayArray.put(oraObj); - if(i == week.length() - 1) { - gen_days.add(dayArray); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - Collections.sort(gen_days, new Comparator() { - - public int compare(JSONArray a, JSONArray b) { - long valA = 0; - long valB = 0; - - try { - valA = (long) new DateTime( a.getJSONObject(0).getString("Datum")).getMillis(); - valB = (long) new DateTime( b.getJSONObject(0).getString("Datum")).getMillis(); - } - catch (JSONException ignored) { - } - - return (int) (valA - valB); - } - }); - - return gen_days; - } - - public static String zeroPad(int value, int padding){ - StringBuilder b = new StringBuilder(); - b.append(value); - while(b.length() < padding){ - b.insert(0,"0"); - } - return b.toString(); - } - - public static Locale getLocale(Context context) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - String loc = dbManager.fetchLocale().getString(0); - dbManager.close(); - - if(loc.equals("hu") || loc.equals("de")) { - return new Locale(loc, loc.toUpperCase()); - } - } catch (Exception e) { - e.printStackTrace(); - } - - return new Locale("en", "GB"); - } - - public static boolean premiumEnabled(Context context) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - String premium_token = dbManager.fetchPremiumToken().getString(0); - String premium_scopes_raw = dbManager.fetchPremiumScopes().getString(0); - dbManager.close(); - - JSONArray arr = new JSONArray(premium_scopes_raw); - List premium_scopes = new ArrayList<>(); - for(int i = 0; i < arr.length(); i++){ - String scope = arr.getString(i); - premium_scopes.add(scope.substring(scope.lastIndexOf('.') + 1)); - } - - if(!premium_token.equals("") && (premium_scopes.contains("*") || premium_scopes.contains("TIMETALBE_WIDGET"))) { - return true; - } - } catch (Exception e) { - e.printStackTrace(); - } - - return false; - } - - public static boolean userLoggedIn(Context context) { - return !lastUserId(context).equals(""); - } - - public static String lastUserId(Context context) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - try { - dbManager.open(); - Cursor cursor = dbManager.fetchLastUser(); - dbManager.close(); - - if(cursor != null && !cursor.getString(0).equals("")) { - String last_user = cursor.getString(0); - return last_user; - } - } catch (Exception e) { - e.printStackTrace(); - } - - return ""; - } - - @Override - public void onEnabled(Context context) { - } - - @Override - public void onDisabled(Context context) { - } +package hu.refilc.naplo.widget_timetable; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build; +import android.util.Log; +import android.view.View; +import android.widget.RemoteViews; +import android.widget.Toast; + +import org.joda.time.DateTime; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.time.DayOfWeek; +import java.time.format.TextStyle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; + +import hu.refilc.naplo.database.DBManager; +import hu.refilc.naplo.MainActivity; +import hu.refilc.naplo.R; + +import hu.refilc.naplo.utils.Week; + +import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; + +import es.antonborri.home_widget.HomeWidgetBackgroundIntent; +import es.antonborri.home_widget.HomeWidgetLaunchIntent; +import es.antonborri.home_widget.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_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_REFRESH = "list_widget.ACTION_WIDGET_CLICK_NAV_REFRESH"; + private static final String ACTION_WIDGET_CLICK_BUY_PREMIUM = "list_widget.ACTION_WIDGET_CLICK_BUY_PREMIUM"; + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, SharedPreferences widgetData) { + for (int i = 0; i < appWidgetIds.length; i++) { + RemoteViews views = generateView(context, appWidgetIds[i]); + + if(premiumEnabled(context) && userLoggedIn(context)) { + int rday = selectDay(context, appWidgetIds[i], 0, true); + views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); + } + + pushUpdate(context, views, appWidgetIds[i]); + } + } + + public static void pushUpdate(Context context, RemoteViews remoteViews, int appWidgetSingleId) { + AppWidgetManager manager = AppWidgetManager.getInstance(context); + + manager.updateAppWidget(appWidgetSingleId, remoteViews); + manager.notifyAppWidgetViewDataChanged(appWidgetSingleId, R.id.widget_list); + } + + public static RemoteViews generateView(Context context, int appId) { + Intent serviceIntent = new Intent(context, WidgetTimetableService.class); + serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appId); + serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); + + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_timetable); + + views.setViewVisibility(R.id.need_premium, View.GONE); + views.setViewVisibility(R.id.need_login, View.GONE); + views.setViewVisibility(R.id.tt_grid_cont, View.GONE); + + if(!userLoggedIn(context)) { + views.setViewVisibility(R.id.need_login, View.VISIBLE); + views.setOnClickPendingIntent(R.id.open_login, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); + } else if(premiumEnabled(context)) { + 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_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_refresh, makePending(context, ACTION_WIDGET_CLICK_NAV_REFRESH, appId)); + views.setRemoteAdapter(R.id.widget_list, serviceIntent); + views.setEmptyView(R.id.widget_list, R.id.empty_view); + } else { + views.setViewVisibility(R.id.need_premium, View.VISIBLE); + views.setOnClickPendingIntent(R.id.buy_premium, makePending(context, ACTION_WIDGET_CLICK_BUY_PREMIUM, appId)); + } + + return views; + } + + static PendingIntent makePending(Context context, String action, int appWidgetId) { + Intent activebtnnext = new Intent(context, WidgetTimetable.class); + activebtnnext.setAction(action); + activebtnnext.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + return PendingIntent.getBroadcast(context, appWidgetId, activebtnnext , PendingIntent.FLAG_IMMUTABLE); + } + + @Override + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + + if(intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { + int appId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + RemoteViews views = generateView(context, appId); + + try { + if(premiumEnabled(context) && userLoggedIn(context)) { + if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_LEFT)) { + int rday = selectDay(context, appId, -1, false); + views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); + + pushUpdate(context, views, appId); + } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_RIGHT)) { + int rday = selectDay(context, appId, 1, false); + views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); + + pushUpdate(context, views, appId); + } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_TODAY)) { + int rday = getToday(context); + setSelectedDay(context, appId, rday); + + views.setTextViewText(R.id.nav_current, convertDayOfWeek(context, rday)); + + pushUpdate(context, views, appId); + } else if (intent.getAction().equals(ACTION_WIDGET_CLICK_NAV_REFRESH)) { + PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("timetable://refresh")); + pendingIntent.send(); + } else if (intent.getAction().equals("android.appwidget.action.APPWIDGET_DELETED")) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + dbManager.deleteWidget(appId); + dbManager.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + if(intent.getAction().equals(ACTION_WIDGET_CLICK_BUY_PREMIUM)) { + PendingIntent pendingIntent = HomeWidgetLaunchIntent.INSTANCE.getActivity(context, MainActivity.class, Uri.parse("settings://premium")); + pendingIntent.send(); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + public static String convertDayOfWeek(Context context, int rday) { + + /*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 = "Unknown"; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Locale loc = getLocale(context); + + if (rday == -1) + return DayOfWeek.of(1).getDisplayName(TextStyle.FULL, loc); + + dayOfWeek = DayOfWeek.of(rday + 1).getDisplayName(TextStyle.FULL, loc); + } + + return dayOfWeek.substring(0, 1).toUpperCase() + dayOfWeek.substring(1).toLowerCase(); + } + + public static void setSelectedDay(Context context, int wid, int day) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + dbManager.update(wid, day); + dbManager.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static int getToday(Context context) { + int rday = new DateTime().getDayOfWeek() - 1; + List s = genJsonDays(context); + + try { + if(checkIsAfter(s, rday)) rday += 1; + } catch (Exception e) { + e.printStackTrace(); + } + return retDay(rday, s.size()); + } + + public static int selectDay(Context context, int wid, int add, Boolean afterSubjects) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + Cursor cursor = dbManager.fetchWidget(wid); + + List s = genJsonDays(context); + int retday = new DateTime().getDayOfWeek() - 1; + + if(cursor.getCount() != 0) retday = retDay(cursor.getInt(1) + add, s.size()); + + if(afterSubjects) if(checkIsAfter(s, retday)) retday += 1; + retday = retDay(retday, s.size()); + + if(cursor.getCount() == 0) dbManager.insertSelDay(wid, retday); + else dbManager.update(wid, retday); + + dbManager.close(); + + return retday; + } catch (Exception e) { + e.printStackTrace(); + } + + return 0; + } + + public static Boolean checkIsAfter(List s, int retday) throws Exception { + retday = retDay(retday, s.size()); + + String vegIdopont = s.get(retday).getJSONObject(s.get(retday).length() - 1).getString("VegIdopont"); + + return new DateTime().isAfter(new DateTime(vegIdopont)); + } + + public static int retDay(int retday, int size) { + if (retday < 0) retday = size - 1; + else if (retday > size - 1) retday = 0; + + return retday; + } + + public static List genJsonDays(Context context) { + List gen_days = new ArrayList<>(); + + DBManager dbManager = new DBManager(context.getApplicationContext()); + try { + dbManager.open(); + Cursor ct = dbManager.fetchTimetable(); + dbManager.close(); + + if(ct.getCount() == 0) { + return gen_days; + } + + JSONObject fecthtt = new JSONObject(ct.getString(0)); + + JSONArray dayArray = new JSONArray(); + String currday = ""; + + String currweek = String.valueOf(Week.current().id()); + + JSONArray week = fecthtt.getJSONArray(currweek); + + for (int i=0; i < week.length(); i++) + { + try { + if(i == 0) currday = week.getJSONObject(0).getString("Datum"); + JSONObject oraObj = week.getJSONObject(i); + + if(!currday.equals(oraObj.getString("Datum"))) { + gen_days.add(dayArray); + currday = week.getJSONObject(i).getString("Datum"); + dayArray = new JSONArray(); + } + + dayArray.put(oraObj); + if(i == week.length() - 1) { + gen_days.add(dayArray); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + Collections.sort(gen_days, new Comparator() { + + public int compare(JSONArray a, JSONArray b) { + long valA = 0; + long valB = 0; + + try { + valA = (long) new DateTime( a.getJSONObject(0).getString("Datum")).getMillis(); + valB = (long) new DateTime( b.getJSONObject(0).getString("Datum")).getMillis(); + } + catch (JSONException ignored) { + } + + return (int) (valA - valB); + } + }); + + return gen_days; + } + + public static String zeroPad(int value, int padding){ + StringBuilder b = new StringBuilder(); + b.append(value); + while(b.length() < padding){ + b.insert(0,"0"); + } + return b.toString(); + } + + public static Locale getLocale(Context context) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + String loc = dbManager.fetchLocale().getString(0); + dbManager.close(); + + if(loc.equals("hu") || loc.equals("de")) { + return new Locale(loc, loc.toUpperCase()); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return new Locale("en", "GB"); + } + + public static boolean premiumEnabled(Context context) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + String premium_token = dbManager.fetchPremiumToken().getString(0); + String premium_scopes_raw = dbManager.fetchPremiumScopes().getString(0); + dbManager.close(); + + JSONArray arr = new JSONArray(premium_scopes_raw); + List premium_scopes = new ArrayList<>(); + for(int i = 0; i < arr.length(); i++){ + String scope = arr.getString(i); + premium_scopes.add(scope.substring(scope.lastIndexOf('.') + 1)); + } + + if(!premium_token.equals("") && (premium_scopes.contains("*") || premium_scopes.contains("TIMETALBE_WIDGET"))) { + return true; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + + public static boolean userLoggedIn(Context context) { + return !lastUserId(context).equals(""); + } + + public static String lastUserId(Context context) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + try { + dbManager.open(); + Cursor cursor = dbManager.fetchLastUser(); + dbManager.close(); + + if(cursor != null && !cursor.getString(0).equals("")) { + String last_user = cursor.getString(0); + return last_user; + } + } catch (Exception e) { + e.printStackTrace(); + } + + return ""; + } + + @Override + public void onEnabled(Context context) { + } + + @Override + public void onDisabled(Context context) { + } } \ No newline at end of file diff --git a/filcnaplo_premium/android/widget_timetable/WidgetTimetableDataProvider.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableDataProvider.java similarity index 97% rename from filcnaplo_premium/android/widget_timetable/WidgetTimetableDataProvider.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableDataProvider.java index 147157a..9ce41dd 100644 --- a/filcnaplo_premium/android/widget_timetable/WidgetTimetableDataProvider.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableDataProvider.java @@ -1,354 +1,354 @@ -package hu.refilc.naplo.widget_timetable; - -import android.appwidget.AppWidgetManager; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.os.Build; -import android.util.Log; -import android.view.View; -import android.widget.RemoteViews; -import android.widget.RemoteViewsService; - -import org.joda.time.DateTime; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import hu.refilc.naplo.database.DBManager; -import hu.refilc.naplo.R; - -public class WidgetTimetableDataProvider implements RemoteViewsService.RemoteViewsFactory { - - private Context context; - private int appWidgetId; - - private int rday = 0; - - private int theme; - - private Integer[] colorValues; - - List day_subjects = new ArrayList<>(); - List lessonIndexes = new ArrayList<>(); - - Item witem; - - /* Default values */ - - static class Item { - int Layout; - - int NumVisibility; - int NameVisibility; - int NameNodescVisibility; - int DescVisibility; - int RoomVisibility; - int TimeVisibility; - - int NumColor; - int NameColor; - int NameNodescColor; - int DescColor; - - 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) { - this.Layout = Layout; - this.NumVisibility = NumVisibility; - this.NameVisibility = NameVisibility; - this.NameNodescVisibility = NameNodescVisibility; - this.DescVisibility = DescVisibility; - this.RoomVisibility = RoomVisibility; - this.TimeVisibility = TimeVisibility; - - this.NumColor = NumColor; - this.NameColor = NameColor; - this.NameNodescColor = NameNodescColor; - this.DescColor = DescColor; - } - } - - static class 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.lessonIndex = lessonIndex; - this.lessonName = lessonName; - this.lessonTopic = lessonTopic; - this.lessonRoom = lessonRoom; - this.lessonStart = lessonStart; - this.lessonEnd = lessonEnd; - this.substituteTeacher = substituteTeacher; - } - } - - Integer[] itemNameNodescPadding = {0, 0, 0, 0}; - - public WidgetTimetableDataProvider(Context context, Intent intent) { - this.context = context; - this.appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); - - this.theme = getThemeAccent(context); - - this.colorValues = new Integer[]{R.color.filc, - R.color.blue_shade300, - R.color.green_shade300, - R.color.lime_shade300, - R.color.yellow_shade300, - R.color.orange_shade300, - R.color.red_shade300, - R.color.pink_shade300, - R.color.purple_shade300}; - - } - - @Override - public void onCreate() { - initData(); - } - - @Override - public void onDataSetChanged() { - initData(); - } - - @Override - public void onDestroy() { - - } - - @Override - public int getCount() { - - return day_subjects.size(); - } - - public void setLayout(final RemoteViews view) { - /* Visibilities */ - 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_nodesc, witem.NameNodescVisibility); - view.setViewVisibility(R.id.tt_item_desc, witem.DescVisibility); - view.setViewVisibility(R.id.tt_item_room, witem.RoomVisibility); - view.setViewVisibility(R.id.tt_item_time, witem.TimeVisibility); - - /* backgroundResources */ - view.setInt(R.id.main_lay, "setBackgroundResource", witem.Layout); - - /* Paddings */ - view.setViewPadding(R.id.tt_item_name_nodesc, witem.NameNodescPadding[0], witem.NameNodescPadding[1], witem.NameNodescPadding[2], witem.NameNodescPadding[3]); - - /* Text Colors */ - 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_nodesc, "setTextColor", getColor(context, witem.NameNodescColor)); - view.setInt(R.id.tt_item_desc, "setTextColor", getColor(context, witem.DescColor)); - } - - public int getColor(Context context, int color) { - return context.getResources().getColor(color); - } - - @Override - public RemoteViews getViewAt(int position) { - RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.timetable_item); - - witem = defaultItem(theme); - - Lesson curr_subject = day_subjects.get(position); - - if (curr_subject.status.equals("empty")) { - witem.NumColor = R.color.text_miss_num; - - witem.TimeVisibility = View.GONE; - witem.RoomVisibility = View.GONE; - - witem.NameNodescColor = R.color.text_miss; - } - - if (!curr_subject.substituteTeacher.equals("null")) { - witem.NumColor = R.color.yellow; - witem.Layout = R.drawable.card_layout_tile_helyetesitett; - } - - if (curr_subject.status.equals("Elmaradt")) { - witem.NumColor = R.color.red; - witem.Layout = R.drawable.card_layout_tile_elmarad; - } else if (curr_subject.status.equals("TanevRendjeEsemeny")) { - witem.NumVisibility = View.GONE; - witem.TimeVisibility = View.GONE; - witem.RoomVisibility = View.GONE; - - witem.NameNodescPadding[0] = 50; - witem.NameNodescPadding[2] = 50; - - witem.NameNodescColor = R.color.text_miss; - } - - if (curr_subject.lessonTopic.equals("null")) { - witem.DescVisibility = View.GONE; - witem.NameVisibility = View.GONE; - - witem.NameNodescVisibility = View.VISIBLE; - } - - setLayout(view); - - String lessonIndexTrailing = curr_subject.lessonIndex.equals("+") ? "" : "."; - - 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_nodesc, curr_subject.lessonName); - view.setTextViewText(R.id.tt_item_desc, curr_subject.lessonTopic); - view.setTextViewText(R.id.tt_item_room, curr_subject.lessonRoom); - 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) + - "\n" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getMinuteOfHour(),2)); - - return view; - } - - @Override - public RemoteViews getLoadingView() { - return null; - } - - @Override - public int getViewTypeCount() { - return 1; - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public boolean hasStableIds() { - return true; - } - - private void initData() { - - theme = getThemeAccent(context); - - rday = WidgetTimetable.selectDay(context, appWidgetId, 0, false); - - day_subjects.clear(); - lessonIndexes.clear(); - - try { - List arr = WidgetTimetable.genJsonDays(context); - - if(arr.isEmpty()) { - return; - } - JSONArray arr_lessons = WidgetTimetable.genJsonDays(context).get(rday); - - for (int i = 0; i < arr_lessons.length(); i++) { - JSONObject obj_lessons = arr_lessons.getJSONObject(i); - - day_subjects.add(jsonToLesson(obj_lessons)); - } - } catch (JSONException e) { - e.printStackTrace(); - } - - if(day_subjects.size() > 0) { - Collections.sort(day_subjects, new Comparator() { - public int compare(Lesson o1, Lesson o2) { - return new DateTime(o1.lessonStart).compareTo(new DateTime(o2.lessonStart)); - } - }); - - for (int i = 0; i < day_subjects.size(); i++) { - if(!day_subjects.get(i).lessonIndex.equals("+")) { - lessonIndexes.add(Integer.valueOf(day_subjects.get(i).lessonIndex)); - } - } - - if(lessonIndexes.size() > 0) { - - int lessonsChecked = Collections.min(lessonIndexes); - int i = 0; - - while(lessonsChecked < Collections.max(lessonIndexes)) { - if(!lessonIndexes.contains(lessonsChecked)) { - day_subjects.add(i, emptyLesson(lessonsChecked)); - } - lessonsChecked++; - i++; - } - } - } - } - - public static Integer getThemeAccent(Context context) { - DBManager dbManager = new DBManager(context.getApplicationContext()); - - try { - dbManager.open(); - Cursor cursor = dbManager.fetchTheme(); - dbManager.close(); - - return cursor.getInt(1); - } catch (Exception e) { - e.printStackTrace(); - } - - return 0; - } - - public Item defaultItem(int theme) { - return new Item( - R.drawable.card_layout_tile, - View.VISIBLE, - View.VISIBLE, - View.INVISIBLE, - View.VISIBLE, - View.VISIBLE, - View.VISIBLE, - colorValues[theme >= colorValues.length ? 0 : theme], - R.color.text, - R.color.text, - R.color.text_desc - ); - } - - public Lesson emptyLesson(int lessonIndex) { - return new Lesson("empty", String.valueOf(lessonIndex), "Lyukasóra", "null", "null", 0, 0, "null"); - } - - public Lesson jsonToLesson(JSONObject json) { - try { - return new Lesson( - json.getJSONObject("Allapot").getString("Nev"), - !json.getString("Oraszam").equals("null") ? json.getString("Oraszam") : "+", - json.getString("Nev"), - json.getString("Tema"), - json.getString("TeremNeve"), - new DateTime(json.getString("KezdetIdopont")).getMillis(), - new DateTime(json.getString("VegIdopont")).getMillis(), - json.getString("HelyettesTanarNeve") - ); - }catch (Exception e) { - Log.d("Filc", "exception: " + e); - }; - - return null; - } +package hu.refilc.naplo.widget_timetable; + +import android.appwidget.AppWidgetManager; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.os.Build; +import android.util.Log; +import android.view.View; +import android.widget.RemoteViews; +import android.widget.RemoteViewsService; + +import org.joda.time.DateTime; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import hu.refilc.naplo.database.DBManager; +import hu.refilc.naplo.R; + +public class WidgetTimetableDataProvider implements RemoteViewsService.RemoteViewsFactory { + + private Context context; + private int appWidgetId; + + private int rday = 0; + + private int theme; + + private Integer[] colorValues; + + List day_subjects = new ArrayList<>(); + List lessonIndexes = new ArrayList<>(); + + Item witem; + + /* Default values */ + + static class Item { + int Layout; + + int NumVisibility; + int NameVisibility; + int NameNodescVisibility; + int DescVisibility; + int RoomVisibility; + int TimeVisibility; + + int NumColor; + int NameColor; + int NameNodescColor; + int DescColor; + + 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) { + this.Layout = Layout; + this.NumVisibility = NumVisibility; + this.NameVisibility = NameVisibility; + this.NameNodescVisibility = NameNodescVisibility; + this.DescVisibility = DescVisibility; + this.RoomVisibility = RoomVisibility; + this.TimeVisibility = TimeVisibility; + + this.NumColor = NumColor; + this.NameColor = NameColor; + this.NameNodescColor = NameNodescColor; + this.DescColor = DescColor; + } + } + + static class 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.lessonIndex = lessonIndex; + this.lessonName = lessonName; + this.lessonTopic = lessonTopic; + this.lessonRoom = lessonRoom; + this.lessonStart = lessonStart; + this.lessonEnd = lessonEnd; + this.substituteTeacher = substituteTeacher; + } + } + + Integer[] itemNameNodescPadding = {0, 0, 0, 0}; + + public WidgetTimetableDataProvider(Context context, Intent intent) { + this.context = context; + this.appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + + this.theme = getThemeAccent(context); + + this.colorValues = new Integer[]{R.color.filc, + R.color.blue_shade300, + R.color.green_shade300, + R.color.lime_shade300, + R.color.yellow_shade300, + R.color.orange_shade300, + R.color.red_shade300, + R.color.pink_shade300, + R.color.purple_shade300}; + + } + + @Override + public void onCreate() { + initData(); + } + + @Override + public void onDataSetChanged() { + initData(); + } + + @Override + public void onDestroy() { + + } + + @Override + public int getCount() { + + return day_subjects.size(); + } + + public void setLayout(final RemoteViews view) { + /* Visibilities */ + 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_nodesc, witem.NameNodescVisibility); + view.setViewVisibility(R.id.tt_item_desc, witem.DescVisibility); + view.setViewVisibility(R.id.tt_item_room, witem.RoomVisibility); + view.setViewVisibility(R.id.tt_item_time, witem.TimeVisibility); + + /* backgroundResources */ + view.setInt(R.id.main_lay, "setBackgroundResource", witem.Layout); + + /* Paddings */ + view.setViewPadding(R.id.tt_item_name_nodesc, witem.NameNodescPadding[0], witem.NameNodescPadding[1], witem.NameNodescPadding[2], witem.NameNodescPadding[3]); + + /* Text Colors */ + 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_nodesc, "setTextColor", getColor(context, witem.NameNodescColor)); + view.setInt(R.id.tt_item_desc, "setTextColor", getColor(context, witem.DescColor)); + } + + public int getColor(Context context, int color) { + return context.getResources().getColor(color); + } + + @Override + public RemoteViews getViewAt(int position) { + RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.timetable_item); + + witem = defaultItem(theme); + + Lesson curr_subject = day_subjects.get(position); + + if (curr_subject.status.equals("empty")) { + witem.NumColor = R.color.text_miss_num; + + witem.TimeVisibility = View.GONE; + witem.RoomVisibility = View.GONE; + + witem.NameNodescColor = R.color.text_miss; + } + + if (!curr_subject.substituteTeacher.equals("null")) { + witem.NumColor = R.color.yellow; + witem.Layout = R.drawable.card_layout_tile_helyetesitett; + } + + if (curr_subject.status.equals("Elmaradt")) { + witem.NumColor = R.color.red; + witem.Layout = R.drawable.card_layout_tile_elmarad; + } else if (curr_subject.status.equals("TanevRendjeEsemeny")) { + witem.NumVisibility = View.GONE; + witem.TimeVisibility = View.GONE; + witem.RoomVisibility = View.GONE; + + witem.NameNodescPadding[0] = 50; + witem.NameNodescPadding[2] = 50; + + witem.NameNodescColor = R.color.text_miss; + } + + if (curr_subject.lessonTopic.equals("null")) { + witem.DescVisibility = View.GONE; + witem.NameVisibility = View.GONE; + + witem.NameNodescVisibility = View.VISIBLE; + } + + setLayout(view); + + String lessonIndexTrailing = curr_subject.lessonIndex.equals("+") ? "" : "."; + + 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_nodesc, curr_subject.lessonName); + view.setTextViewText(R.id.tt_item_desc, curr_subject.lessonTopic); + view.setTextViewText(R.id.tt_item_room, curr_subject.lessonRoom); + 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) + + "\n" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getHourOfDay(), 2) + ":" + WidgetTimetable.zeroPad(new DateTime(curr_subject.lessonEnd).getMinuteOfHour(),2)); + + return view; + } + + @Override + public RemoteViews getLoadingView() { + return null; + } + + @Override + public int getViewTypeCount() { + return 1; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public boolean hasStableIds() { + return true; + } + + private void initData() { + + theme = getThemeAccent(context); + + rday = WidgetTimetable.selectDay(context, appWidgetId, 0, false); + + day_subjects.clear(); + lessonIndexes.clear(); + + try { + List arr = WidgetTimetable.genJsonDays(context); + + if(arr.isEmpty()) { + return; + } + JSONArray arr_lessons = WidgetTimetable.genJsonDays(context).get(rday); + + for (int i = 0; i < arr_lessons.length(); i++) { + JSONObject obj_lessons = arr_lessons.getJSONObject(i); + + day_subjects.add(jsonToLesson(obj_lessons)); + } + } catch (JSONException e) { + e.printStackTrace(); + } + + if(day_subjects.size() > 0) { + Collections.sort(day_subjects, new Comparator() { + public int compare(Lesson o1, Lesson o2) { + return new DateTime(o1.lessonStart).compareTo(new DateTime(o2.lessonStart)); + } + }); + + for (int i = 0; i < day_subjects.size(); i++) { + if(!day_subjects.get(i).lessonIndex.equals("+")) { + lessonIndexes.add(Integer.valueOf(day_subjects.get(i).lessonIndex)); + } + } + + if(lessonIndexes.size() > 0) { + + int lessonsChecked = Collections.min(lessonIndexes); + int i = 0; + + while(lessonsChecked < Collections.max(lessonIndexes)) { + if(!lessonIndexes.contains(lessonsChecked)) { + day_subjects.add(i, emptyLesson(lessonsChecked)); + } + lessonsChecked++; + i++; + } + } + } + } + + public static Integer getThemeAccent(Context context) { + DBManager dbManager = new DBManager(context.getApplicationContext()); + + try { + dbManager.open(); + Cursor cursor = dbManager.fetchTheme(); + dbManager.close(); + + return cursor.getInt(1); + } catch (Exception e) { + e.printStackTrace(); + } + + return 0; + } + + public Item defaultItem(int theme) { + return new Item( + R.drawable.card_layout_tile, + View.VISIBLE, + View.VISIBLE, + View.INVISIBLE, + View.VISIBLE, + View.VISIBLE, + View.VISIBLE, + colorValues[theme >= colorValues.length ? 0 : theme], + R.color.text, + R.color.text, + R.color.text_desc + ); + } + + public Lesson emptyLesson(int lessonIndex) { + return new Lesson("empty", String.valueOf(lessonIndex), "Lyukasóra", "null", "null", 0, 0, "null"); + } + + public Lesson jsonToLesson(JSONObject json) { + try { + return new Lesson( + json.getJSONObject("Allapot").getString("Nev"), + !json.getString("Oraszam").equals("null") ? json.getString("Oraszam") : "+", + json.getString("Nev"), + json.getString("Tema"), + json.getString("TeremNeve"), + new DateTime(json.getString("KezdetIdopont")).getMillis(), + new DateTime(json.getString("VegIdopont")).getMillis(), + json.getString("HelyettesTanarNeve") + ); + }catch (Exception e) { + Log.d("Filc", "exception: " + e); + }; + + return null; + } } \ No newline at end of file diff --git a/filcnaplo_premium/android/widget_timetable/WidgetTimetableService.java b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableService.java similarity index 96% rename from filcnaplo_premium/android/widget_timetable/WidgetTimetableService.java rename to filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableService.java index 01a5f90..1864174 100644 --- a/filcnaplo_premium/android/widget_timetable/WidgetTimetableService.java +++ b/filcnaplo/android/app/src/main/java/hu/refilc/naplo/widget_timetable/WidgetTimetableService.java @@ -1,12 +1,12 @@ -package hu.refilc.naplo.widget_timetable; - -import android.content.Intent; -import android.os.Build; -import android.widget.RemoteViewsService; - -public class WidgetTimetableService extends RemoteViewsService { - @Override - public RemoteViewsFactory onGetViewFactory(Intent intent) { - return new WidgetTimetableDataProvider(getApplicationContext(), intent); - } -} +package hu.refilc.naplo.widget_timetable; + +import android.content.Intent; +import android.os.Build; +import android.widget.RemoteViewsService; + +public class WidgetTimetableService extends RemoteViewsService { + @Override + public RemoteViewsFactory onGetViewFactory(Intent intent) { + return new WidgetTimetableDataProvider(getApplicationContext(), intent); + } +} \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/drawable-hdpi/tinta_icon.png b/filcnaplo/android/app/src/main/res/drawable-hdpi/tinta_icon.png deleted file mode 100644 index bdb6771..0000000 Binary files a/filcnaplo/android/app/src/main/res/drawable-hdpi/tinta_icon.png and /dev/null differ diff --git a/filcnaplo/android/app/src/main/res/drawable-v21/launch_gradient_background.xml b/filcnaplo/android/app/src/main/res/drawable-v21/launch_gradient_background.xml deleted file mode 100644 index 67e425a..0000000 --- a/filcnaplo/android/app/src/main/res/drawable-v21/launch_gradient_background.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_background.xml b/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_background.xml deleted file mode 100644 index 293a93c..0000000 --- a/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_gradient_background.xml b/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_gradient_background.xml deleted file mode 100644 index 67e425a..0000000 --- a/filcnaplo/android/app/src/main/res/drawable-xhdpi/launch_gradient_background.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/drawable/launch_gradient_background.xml b/filcnaplo/android/app/src/main/res/drawable/launch_gradient_background.xml deleted file mode 100644 index 67e425a..0000000 --- a/filcnaplo/android/app/src/main/res/drawable/launch_gradient_background.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/layout/timetable_item.xml b/filcnaplo/android/app/src/main/res/layout/timetable_item.xml index 6b2a7f8..aa23af8 100644 --- a/filcnaplo/android/app/src/main/res/layout/timetable_item.xml +++ b/filcnaplo/android/app/src/main/res/layout/timetable_item.xml @@ -1,5 +1,6 @@ + tools:ignore="HardcodedText" /> + android:layout_toEndOf="@id/tt_item_num" + android:textColor="@color/text" + tools:ignore="HardcodedText" /> + android:layout_toEndOf="@id/tt_item_num" + android:textColor="@color/text" + tools:ignore="HardcodedText" /> + android:textColor="@color/text_desc" + tools:ignore="HardcodedText" /> + android:layout_toStartOf="@id/tt_item_time" + android:textColor="@color/text_desc" + tools:ignore="HardcodedText" /> + android:layout_alignParentEnd="true" + android:textColor="@color/white" + tools:ignore="HardcodedText" /> \ No newline at end of file diff --git a/filcnaplo/android/app/src/main/res/layout/widget_timetable.xml b/filcnaplo/android/app/src/main/res/layout/widget_timetable.xml index e10fda1..69b80b0 100644 --- a/filcnaplo/android/app/src/main/res/layout/widget_timetable.xml +++ b/filcnaplo/android/app/src/main/res/layout/widget_timetable.xml @@ -19,10 +19,12 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" - android:text="Empty" + android:text="Üres / Empty" + android:background="@drawable/widget_card_bottom_dark" android:textColor="@color/text" android:textSize="20sp" - android:textStyle="bold" /> + android:textStyle="bold" + tools:ignore="HardcodedText" /> + + android:focusable="true" /> + android:focusable="true" /> + android:focusable="true" /> + android:textSize="22sp" + android:textStyle="bold" + tools:ignore="HardcodedText" /> @@ -131,8 +139,9 @@ android:text="A widget használatához, bejelentkezés szükséges." android:textColor="@color/black" android:paddingTop="10dp" - android:textSize="17dp" - android:textStyle="bold" /> + android:textSize="17sp" + android:textStyle="bold" + tools:ignore="HardcodedText" />