diff --git a/app-data/.gitignore b/app-data/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app-data/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app-data/build.gradle.kts b/app-data/build.gradle.kts new file mode 100644 index 0000000..0c5acad --- /dev/null +++ b/app-data/build.gradle.kts @@ -0,0 +1,38 @@ +plugins { + id("com.android.library") +} + +android { + namespace = "ru.plumsoftware.data" + compileSdk = 34 + + defaultConfig { + minSdk = 22 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("com.google.android.material:material:1.12.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") +} \ No newline at end of file diff --git a/app-data/consumer-rules.pro b/app-data/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/app-data/proguard-rules.pro b/app-data/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app-data/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app-data/src/androidTest/java/ru/plumsoftware/data/ExampleInstrumentedTest.java b/app-data/src/androidTest/java/ru/plumsoftware/data/ExampleInstrumentedTest.java new file mode 100644 index 0000000..c629b50 --- /dev/null +++ b/app-data/src/androidTest/java/ru/plumsoftware/data/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package ru.plumsoftware.data; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("ru.plumsoftware.data.test", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app-data/src/main/AndroidManifest.xml b/app-data/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/app-data/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/ru/plumsoftware/notebook/databases/SQLiteDatabaseManager.java b/app-data/src/main/java/ru/plumsoftware/data/database/SQLiteDatabaseManager.java similarity index 69% rename from app/src/main/java/ru/plumsoftware/notebook/databases/SQLiteDatabaseManager.java rename to app-data/src/main/java/ru/plumsoftware/data/database/SQLiteDatabaseManager.java index 66273a9..47f5de7 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/databases/SQLiteDatabaseManager.java +++ b/app-data/src/main/java/ru/plumsoftware/data/database/SQLiteDatabaseManager.java @@ -1,13 +1,14 @@ -package ru.plumsoftware.notebook.databases; +package ru.plumsoftware.data.database; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -import android.util.Log; + +import ru.plumsoftware.data.model.database.DatabaseConstants; public class SQLiteDatabaseManager extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 5; - public static final String DATABASE_NAME = DatabaseConstants.DATABASE_NAME; + private static final int DATABASE_VERSION = 5; + private static final String DATABASE_NAME = DatabaseConstants.DATABASE_NAME; public SQLiteDatabaseManager(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -21,23 +22,15 @@ public void onCreate(SQLiteDatabase db) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (newVersion > oldVersion) { String tempTable = "temp_table"; - - // Создаем временную таблицу и копируем данные db.execSQL("CREATE TABLE " + tempTable + " AS SELECT * FROM " + DatabaseConstants._NOTES_TABLE_NAME); - - // Удаляем исходную таблицу db.execSQL(DatabaseConstants.DELETE_NOTES_TABLE); - - // Создаем новую таблицу с новыми полями db.execSQL(DatabaseConstants.CREATE_NOTES_TABLE); db.execSQL("ALTER TABLE " + tempTable + " ADD " + DatabaseConstants._CHANNEL_ID + " TEXT;"); db.execSQL("ALTER TABLE " + tempTable + " ADD " + DatabaseConstants._IS_NOTIFY + " INTEGER;"); - // Копируем данные из временной таблицы в новую таблицу db.execSQL("INSERT INTO " + DatabaseConstants._NOTES_TABLE_NAME + " SELECT * FROM " + tempTable); - // Удаляем временную таблицу db.execSQL("DROP TABLE IF EXISTS " + tempTable); } } diff --git a/app/src/main/java/ru/plumsoftware/notebook/databases/DatabaseConstants.java b/app-data/src/main/java/ru/plumsoftware/data/model/database/DatabaseConstants.java similarity index 98% rename from app/src/main/java/ru/plumsoftware/notebook/databases/DatabaseConstants.java rename to app-data/src/main/java/ru/plumsoftware/data/model/database/DatabaseConstants.java index 38e3a34..e0726cc 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/databases/DatabaseConstants.java +++ b/app-data/src/main/java/ru/plumsoftware/data/model/database/DatabaseConstants.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.databases; +package ru.plumsoftware.data.model.database; import android.provider.BaseColumns; diff --git a/app/src/main/java/ru/plumsoftware/notebook/data/items/Colors.java b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Colors.java similarity index 57% rename from app/src/main/java/ru/plumsoftware/notebook/data/items/Colors.java rename to app-data/src/main/java/ru/plumsoftware/data/model/ui/Colors.java index e467118..3ab3b97 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/data/items/Colors.java +++ b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Colors.java @@ -1,7 +1,9 @@ -package ru.plumsoftware.notebook.data.items; +package ru.plumsoftware.data.model.ui; + +import androidx.annotation.ColorRes; public class Colors { - private int colorRes; + @ColorRes private final int colorRes; public Colors(int colorRes) { this.colorRes = colorRes; diff --git a/app/src/main/java/ru/plumsoftware/notebook/data/items/Note.java b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Note.java similarity index 96% rename from app/src/main/java/ru/plumsoftware/notebook/data/items/Note.java rename to app-data/src/main/java/ru/plumsoftware/data/model/ui/Note.java index 894b4ea..79a5fc9 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/data/items/Note.java +++ b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Note.java @@ -99,13 +99,15 @@ // this.color = color; // } //} -package ru.plumsoftware.notebook.data.items; +package ru.plumsoftware.data.model.ui; import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.NonNull; +import org.jetbrains.annotations.Contract; + import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -140,7 +142,7 @@ public Note( this.opacity = opacity; } - public Note(Parcel in) { + public Note(@NonNull Parcel in) { id = in.readInt(); count = in.readInt(); notePromoResId = in.readInt(); @@ -339,7 +341,7 @@ public int describeContents() { } @Override - public void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(id); dest.writeInt(count); dest.writeInt(notePromoResId); @@ -355,11 +357,15 @@ public void writeToParcel(Parcel dest, int flags) { } public static final Creator CREATOR = new Creator() { + @NonNull + @Contract("_ -> new") @Override public Note createFromParcel(Parcel in) { return new Note(in); } + @NonNull + @Contract(value = "_ -> new", pure = true) @Override public Note[] newArray(int size) { return new Note[size]; diff --git a/app/src/main/java/ru/plumsoftware/notebook/data/items/Shape.java b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Shape.java similarity index 57% rename from app/src/main/java/ru/plumsoftware/notebook/data/items/Shape.java rename to app-data/src/main/java/ru/plumsoftware/data/model/ui/Shape.java index e62156a..1bf29a5 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/data/items/Shape.java +++ b/app-data/src/main/java/ru/plumsoftware/data/model/ui/Shape.java @@ -1,7 +1,9 @@ -package ru.plumsoftware.notebook.data.items; +package ru.plumsoftware.data.model.ui; + +import androidx.annotation.DrawableRes; public class Shape { - private int shapeRes; + @DrawableRes private int shapeRes; public Shape(int shapeRes) { this.shapeRes = shapeRes; diff --git a/app-data/src/test/java/ru/plumsoftware/data/ExampleUnitTest.java b/app-data/src/test/java/ru/plumsoftware/data/ExampleUnitTest.java new file mode 100644 index 0000000..d48a919 --- /dev/null +++ b/app-data/src/test/java/ru/plumsoftware/data/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package ru.plumsoftware.data; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/app-domain/.gitignore b/app-domain/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app-domain/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app-domain/build.gradle.kts b/app-domain/build.gradle.kts new file mode 100644 index 0000000..e103928 --- /dev/null +++ b/app-domain/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("java-library") +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} \ No newline at end of file diff --git a/app-domain/src/main/java/ru/plumsoftware/domain/MyClass.java b/app-domain/src/main/java/ru/plumsoftware/domain/MyClass.java new file mode 100644 index 0000000..3e92721 --- /dev/null +++ b/app-domain/src/main/java/ru/plumsoftware/domain/MyClass.java @@ -0,0 +1,4 @@ +package ru.plumsoftware.domain; + +public class MyClass { +} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e580416..8c34522 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,4 +56,8 @@ dependencies { //Analytics implementation 'com.google.firebase:firebase-analytics:22.1.0' + + //Modules + implementation project(':app-domain') + implementation project(':app-data') } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2e2c8bf..afee53e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,12 +5,13 @@ - + + - - - @@ -46,12 +40,13 @@ - @@ -60,7 +55,7 @@ @@ -68,7 +63,7 @@ diff --git a/app/src/main/java/ru/plumsoftware/notebook/activities/MainMenuActivity.java b/app/src/main/java/ru/plumsoftware/notebook/activities/MainMenuActivity.java deleted file mode 100644 index a81d645..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/activities/MainMenuActivity.java +++ /dev/null @@ -1,168 +0,0 @@ -package ru.plumsoftware.notebook.activities; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.cardview.widget.CardView; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import com.google.firebase.analytics.FirebaseAnalytics; -import com.yandex.mobile.ads.common.AdRequestError; -import com.yandex.mobile.ads.common.ImpressionData; -import com.yandex.mobile.ads.common.InitializationListener; -import com.yandex.mobile.ads.common.MobileAds; -import com.yandex.mobile.ads.nativeads.MediaView; -import com.yandex.mobile.ads.nativeads.NativeAd; -import com.yandex.mobile.ads.nativeads.NativeAdEventListener; -import com.yandex.mobile.ads.nativeads.NativeAdException; -import com.yandex.mobile.ads.nativeads.NativeAdRequestConfiguration; -import com.yandex.mobile.ads.nativeads.NativeAdView; -import com.yandex.mobile.ads.nativeads.NativeAdViewBinder; -import com.yandex.mobile.ads.nativeads.NativeBulkAdLoadListener; -import com.yandex.mobile.ads.nativeads.NativeBulkAdLoader; - -import java.util.List; - -import ru.plumsoftware.notebook.fragments.NotepadFragment; -import ru.plumsoftware.notebook.dialogs.ProgressDialog; -import ru.plumsoftware.notebook.R; - -public class MainMenuActivity extends AppCompatActivity { - private FirebaseAnalytics mFirebaseAnalytics; - private Context context; - private ProgressDialog progressDialog; - private LinearLayout l1, l2; - - private CardView adsCard; - private NativeAdView mNativeAdView; - private MediaView mediaView; - private TextView age; - private TextView bodyView; - private TextView call_to_action; - private TextView priceView; - private TextView storeView; - private TextView tvHeadline; - private TextView warning; - private TextView domain; - private ImageView favicon; - private ImageView imageViewFeedback; - - @SuppressLint("MissingInflatedId") - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main_menu_layout); - - //Native ads - mNativeAdView = (NativeAdView) findViewById(R.id.nativeAdView); - mediaView = (MediaView) findViewById(R.id.media); - age = (TextView) findViewById(R.id.age); - bodyView = (TextView) findViewById(R.id.tvAdvertiser); - call_to_action = (TextView) findViewById(R.id.btnVisitSite); - domain = (TextView) findViewById(R.id.textViewDomain); - favicon = (ImageView) findViewById(R.id.adsPromo); - imageViewFeedback = (ImageView) findViewById(R.id.imageViewFeedback); - priceView = (TextView) findViewById(R.id.priceView); - storeView = (TextView) findViewById(R.id.storeView); - tvHeadline = (TextView) findViewById(R.id.tvHeadline); - warning = (TextView) findViewById(R.id.textViewWarning); - adsCard = (CardView) findViewById(R.id.cardView2); - -// Variables - context = MainMenuActivity.this; - progressDialog = new ProgressDialog(context); - - l1 = (LinearLayout) findViewById(R.id.l1); - l2 = (LinearLayout) findViewById(R.id.l2); - -// Get instance - mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); - -// ADS - MobileAds.initialize(context, new InitializationListener() { - @Override - public void onInitializationCompleted() { - - } - }); - progressDialog.showDialog(); - adsCard.setVisibility(View.GONE); - final NativeBulkAdLoader nativeBulkAdLoader = new NativeBulkAdLoader(context); - nativeBulkAdLoader.setNativeBulkAdLoadListener(new NativeBulkAdLoadListener() { - @Override - public void onAdsLoaded(@NonNull final List nativeAds) { - for (final NativeAd nativeAd : nativeAds) { - final NativeAdViewBinder nativeAdViewBinder = new NativeAdViewBinder.Builder(mNativeAdView) - .setAgeView(age) - .setBodyView(bodyView) - .setCallToActionView(call_to_action) - .setDomainView(domain) - //.setFaviconView(notesViewHolder.favicon) - .setFeedbackView(imageViewFeedback) - .setIconView(favicon) - .setMediaView(mediaView) - .setPriceView(priceView) - //.setRatingView((MyRatingView) findViewById(R.id.rating)) - //.setReviewCountView((TextView) findViewById(R.id.review_count)) - .setSponsoredView(storeView) - .setTitleView(tvHeadline) - .setWarningView(warning) - .build(); - - try { - nativeAd.bindNativeAd(nativeAdViewBinder); - nativeAd.setNativeAdEventListener(new NativeAdEventListener() { - @Override - public void onAdClicked() { - - } - - @Override - public void onLeftApplication() { - - } - - @Override - public void onReturnedToApplication() { - - } - - @Override - public void onImpression(@Nullable ImpressionData impressionData) { - - } - }); - mNativeAdView.setVisibility(View.VISIBLE); - } catch (final NativeAdException exception) { - Toast.makeText(context, exception.toString(), Toast.LENGTH_LONG).show(); - } - } - progressDialog.dismiss(); - } - - @Override - public void onAdsFailedToLoad(@NonNull final AdRequestError error) { - adsCard.setVisibility(View.GONE); - } - }); - - final NativeAdRequestConfiguration nativeAdRequestConfiguration = new NativeAdRequestConfiguration.Builder("R-M-1957919-1").build(); - nativeBulkAdLoader.loadAds(nativeAdRequestConfiguration, 1); - -// Clickers - l1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new NotepadFragment()).commit(); - } - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/plumsoftware/notebook/adapters/GroupAdapter.java b/app/src/main/java/ru/plumsoftware/notebook/adapters/GroupAdapter.java deleted file mode 100644 index 1286f34..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/adapters/GroupAdapter.java +++ /dev/null @@ -1,233 +0,0 @@ -package ru.plumsoftware.notebook.adapters; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.VibrationEffect; -import android.os.Vibrator; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.PopupMenu; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.cardview.widget.CardView; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.ArrayList; -import java.util.List; - -import ru.plumsoftware.notebook.activities.MainActivity; -import ru.plumsoftware.notebook.activities.NotepadActivity; -import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.data.items.Group; -import ru.plumsoftware.notebook.databases.DatabaseConstants; - -public class GroupAdapter extends RecyclerView.Adapter { - private Context context; - private Activity activity; - private List groupList; - private int mode = 0; - public static List addedGroups = new ArrayList<>(); - - public GroupAdapter(Context context, Activity activity, List groupList) { - this.context = context; - this.activity = activity; - this.groupList = groupList; - } - - public GroupAdapter(Context context, Activity activity, List groupList, int mode) { - this.context = context; - this.activity = activity; - this.groupList = groupList; - this.mode = mode; - } - - @NonNull - @Override - public GroupViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new GroupViewHolder(LayoutInflater.from(context).inflate(R.layout.group_item_layout, parent, false)); - } - - @Override - public void onBindViewHolder(@NonNull GroupViewHolder holder, int position) { - Group group = groupList.get(position); - - holder.cardView.setCardBackgroundColor(group.getColor()); - holder.textView.setText(group.getName()); - - final int[] color = {group.getColor()}; - -// Clickers - holder.cardView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE)); - } - showPopupMenu(view, group); - return false; - } - }); - holder.cardView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { -// BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context, R.style.BottomSheetTheme); -// bottomSheetDialog.setContentView(R.layout.add_group_layout); -// bottomSheetDialog.setCancelable(true); -// bottomSheetDialog.setDismissWithAnimation(true); -// -// ImageButton addColor = (ImageButton) bottomSheetDialog.findViewById(R.id.noteColor); -// ImageButton btnDone = (ImageButton) bottomSheetDialog.findViewById(R.id.btnDone); -// EditText tvTitle = (EditText) bottomSheetDialog.findViewById(R.id.Title); -// CardView cardViewBtnDone = (CardView) bottomSheetDialog.findViewById(R.id.cardBtnDone); -// -// color[0] = group.getColor(); -// -// Objects.requireNonNull(cardViewBtnDone).setCardBackgroundColor(color[0]); -// -// bottomSheetDialog.show(); -// -// //Color -// Objects.requireNonNull(addColor).setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(context, R.style.BottomSheetTheme); -// bottomSheetDialog1.setContentView(R.layout.color_picker); -// bottomSheetDialog1.setCancelable(true); -// bottomSheetDialog1.setDismissWithAnimation(true); -// -// GridView colorGridView = (GridView) bottomSheetDialog1.findViewById(R.id.colorGridView); -// -// ArrayList colors = new ArrayList<>(); -// colors.add(new Colors(context.getResources().getColor(R.color.note_blue))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_green))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_orange))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_pink))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_purple))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_red))); -// colors.add(new Colors(context.getResources().getColor(R.color.note_yellow))); -// -// ColorAdapter colorAdapter = new ColorAdapter(context, 0, colors); -// Objects.requireNonNull(colorGridView).setAdapter(colorAdapter); -// -// bottomSheetDialog1.show(); -// -// //Clicker -// colorGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { -// @Override -// public void onItemClick(AdapterView parent, View view, int position, long id) { -// color[0] = colors.get(position).getColorRes(); -// bottomSheetDialog1.dismiss(); -// -// cardViewBtnDone.setCardBackgroundColor(color[0]); -// } -// }); -// } -// }); -// -// Objects.requireNonNull(tvTitle).setText(group.getName()); -// -// //Done -// Objects.requireNonNull(btnDone).setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// String name = Objects.requireNonNull(tvTitle).getText().toString(); -// -// ContentValues contentValues = new ContentValues(); -// contentValues.put(DatabaseConstants._GROUP_NAME, name); -// contentValues.put(DatabaseConstants._NOTE_COLOR, color[0]); -// contentValues.put(DatabaseConstants._ADD_NOTE_TIME, 0); -// contentValues.put(DatabaseConstants._ADD_NOTE_TIME, System.currentTimeMillis()); -// //MainActivity.sqLiteDatabaseNotes.update(DatabaseConstants._GROUPS_TABLE_NAME, contentValues, DatabaseConstants._ADD_NOTE_TIME + " = ?", new String[]{Long.toString(note.getAddNoteTime())}); -// try { -// NotepadActivity.reloadRecyclerView(context, activity); -// } catch (Exception e){ -// e.printStackTrace(); -// } -// -// bottomSheetDialog.dismiss(); -// } -// }); -// -// bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { -// @Override -// public void onDismiss(DialogInterface dialog) { -// activity.startActivity(new Intent(context, NotepadActivity.class)); -// activity.overridePendingTransition(0, 0); -// activity.finish(); -// } -// }); - switch (mode) { - case 0: - if (!addedGroups.contains(group)) { - addedGroups.add(group); - Toast.makeText(context, "Записка будет добавлена в группу: " + group.getName() + ". Сохраните изменения.", Toast.LENGTH_SHORT).show(); - } - break; - case 1: - activity.startActivity(new Intent(context, NotepadActivity.class).putExtra("group", group.getName())); - activity.overridePendingTransition(0, 0); - break; - } - } - }); - } - - @Override - public int getItemCount() { - return groupList.size(); - } - - private void showPopupMenu(View v, Group group) { - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.popup_menu_3); - - popupMenu - .setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @SuppressLint("NonConstantResourceId") - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.delete: - MainActivity.sqLiteDatabaseNotes.delete(DatabaseConstants._GROUPS_TABLE_NAME, DatabaseConstants._GROUP_NAME + " = ? ", new String[]{group.getName()}); - try { - //NotepadActivity.reloadRecyclerViewGroups(context, activity); - } catch (Exception e) { - e.printStackTrace(); - } - return true; - default: - return false; - } - } - }); - - popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { - @Override - public void onDismiss(PopupMenu menu) { - - } - }); - popupMenu.show(); - } -} - -class GroupViewHolder extends RecyclerView.ViewHolder { - protected CardView cardView; - protected TextView textView; - - - public GroupViewHolder(@NonNull View itemView) { - super(itemView); - - cardView = (CardView) itemView.findViewById(R.id.cardView1); - textView = (TextView) itemView.findViewById(R.id.textViewNoteName); - } -} diff --git a/app/src/main/java/ru/plumsoftware/notebook/data/items/Group.java b/app/src/main/java/ru/plumsoftware/notebook/data/items/Group.java deleted file mode 100644 index a89c216..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/data/items/Group.java +++ /dev/null @@ -1,55 +0,0 @@ -package ru.plumsoftware.notebook.data.items; - -public class Group { - private String name; - private int id, color; - private long addGroup, addNote; - - public Group(String name, int id, int color, long addGroup, long addNote) { - this.name = name; - this.id = id; - this.color = color; - this.addGroup = addGroup; - this.addNote = addNote; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getColor() { - return color; - } - - public void setColor(int color) { - this.color = color; - } - - public long getAddGroup() { - return addGroup; - } - - public void setAddGroup(long addGroup) { - this.addGroup = addGroup; - } - - public long getAddNote() { - return addNote; - } - - public void setAddNote(long addNote) { - this.addNote = addNote; - } -} diff --git a/app/src/main/java/ru/plumsoftware/notebook/fragments/NotepadFragment.java b/app/src/main/java/ru/plumsoftware/notebook/fragments/NotepadFragment.java deleted file mode 100644 index fa0e10a..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/fragments/NotepadFragment.java +++ /dev/null @@ -1,514 +0,0 @@ -package ru.plumsoftware.notebook.fragments; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.ContentValues; -import android.content.Context; -import android.content.DialogInterface; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.graphics.Color; -import android.os.Bundle; - -import androidx.cardview.widget.CardView; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.StaggeredGridLayoutManager; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.EditText; -import android.widget.GridView; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.SearchView; - -import com.google.android.material.bottomsheet.BottomSheetDialog; -import com.google.android.material.snackbar.Snackbar; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Objects; - -import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.adapters.ColorAdapter; -import ru.plumsoftware.notebook.adapters.NoteAdapter; -import ru.plumsoftware.notebook.adapters.OpacityAdapter; -import ru.plumsoftware.notebook.data.items.Colors; -import ru.plumsoftware.notebook.data.items.Note; -import ru.plumsoftware.notebook.data.items.Shape; -import ru.plumsoftware.notebook.databases.DatabaseConstants; -import ru.plumsoftware.notebook.databases.SQLiteDatabaseManager; - -public class NotepadFragment extends Fragment { - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - private String mParam1; - private String mParam2; - - public static SQLiteDatabase sqLiteDatabaseNotes; - private static RecyclerView recyclerViewNotes; - private static boolean isList = true; - private int - color, - opacityRes = R.drawable.ic_coffee; - - public NotepadFragment() { - } - - public static NotepadFragment newInstance(String param1, String param2) { - NotepadFragment fragment = new NotepadFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - } - - @SuppressLint({"MissingInflatedId", "LocalSuppress"}) - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_notepad, container, false); - -// FVI - SearchView searchView = (SearchView) view.findViewById(R.id.searchView); - recyclerViewNotes = (RecyclerView) view.findViewById(R.id.recyclerViewNotes); - ImageView filterAsList = (ImageView) view.findViewById(R.id.filterAsList); - ImageButton addNote = (ImageButton) view.findViewById(R.id.addNote); - ConstraintLayout layout = (ConstraintLayout) view.findViewById(R.id.layout); - -// Blur - -// Data - SQLiteDatabaseManager sqLiteDatabaseManager = new SQLiteDatabaseManager(getContext()); - sqLiteDatabaseNotes = sqLiteDatabaseManager.getWritableDatabase(); - NoteAdapter noteAdapter = new NoteAdapter(getContext(), getActivity(), loadNotes(getContext()), 1); - recyclerViewNotes.setHasFixedSize(true); - recyclerViewNotes.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerViewNotes.setAdapter(noteAdapter); - filterAsList.setImageResource(R.drawable.ic_baseline_filter_list); - - color = getResources().getColor(R.color.note_blue); - -// Clickers - filterAsList.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (isList) { - isList = false; - - recyclerViewNotes.setVisibility(View.GONE); - NoteAdapter noteAdapter = new NoteAdapter(getContext(), getActivity(), loadNotes(getContext()), 1); - recyclerViewNotes.setHasFixedSize(true); - recyclerViewNotes.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); - recyclerViewNotes.setAdapter(noteAdapter); - recyclerViewNotes.setVisibility(View.VISIBLE); - - filterAsList.setImageResource(R.drawable.ic_table_rows); - } else { - isList = true; - - recyclerViewNotes.setVisibility(View.GONE); - NoteAdapter noteAdapter = new NoteAdapter(getContext(), getActivity(), loadNotes(getContext()), 1); - recyclerViewNotes.setHasFixedSize(true); - recyclerViewNotes.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerViewNotes.setAdapter(noteAdapter); - recyclerViewNotes.setVisibility(View.VISIBLE); - - filterAsList.setImageResource(R.drawable.ic_baseline_filter_list); - } - } - }); - - addNote.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(requireContext(), R.style.BottomSheetTheme); - bottomSheetDialog.setContentView(R.layout.add_note_layout); - bottomSheetDialog.setCancelable(true); - bottomSheetDialog.setDismissWithAnimation(true); - - ImageButton addOpacity = (ImageButton) bottomSheetDialog.findViewById(R.id.noteOpacity); - ImageButton addColor = (ImageButton) bottomSheetDialog.findViewById(R.id.noteColor); - ImageButton btnDone = (ImageButton) bottomSheetDialog.findViewById(R.id.btnDone1); - EditText tvTitle = (EditText) bottomSheetDialog.findViewById(R.id.Title); - EditText tvText = (EditText) bottomSheetDialog.findViewById(R.id.Text); - CardView cardViewBtnDone = (CardView) bottomSheetDialog.findViewById(R.id.cardBtnDone1); - - Objects.requireNonNull(cardViewBtnDone).setCardBackgroundColor(color); - - bottomSheetDialog.show(); - - //Clickers - - //Color - Objects.requireNonNull(addColor).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(requireContext(), R.style.BottomSheetTheme); - bottomSheetDialog1.setContentView(R.layout.color_picker); - bottomSheetDialog1.setCancelable(true); - bottomSheetDialog1.setDismissWithAnimation(true); - - GridView colorGridView = (GridView) bottomSheetDialog1.findViewById(R.id.colorGridView); - - ArrayList colors = new ArrayList<>(); - colors.add(new Colors(getResources().getColor(R.color.note_blue))); - colors.add(new Colors(getResources().getColor(R.color.note_green))); - colors.add(new Colors(getResources().getColor(R.color.note_orange))); - colors.add(new Colors(getResources().getColor(R.color.note_pink))); - colors.add(new Colors(getResources().getColor(R.color.note_purple))); - colors.add(new Colors(getResources().getColor(R.color.note_red))); - colors.add(new Colors(getResources().getColor(R.color.note_yellow))); - - ColorAdapter colorAdapter = new ColorAdapter(getContext(), 0, colors); - Objects.requireNonNull(colorGridView).setAdapter(colorAdapter); - - bottomSheetDialog1.show(); - - //Clicker - colorGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - color = colors.get(position).getColorRes(); - bottomSheetDialog1.dismiss(); - - cardViewBtnDone.setCardBackgroundColor(color); - } - }); - } - }); - - //Opacity - Objects.requireNonNull(addOpacity).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - BottomSheetDialog bottomSheetDialog1 = new BottomSheetDialog(requireContext(), R.style.BottomSheetTheme); - bottomSheetDialog1.setContentView(R.layout.color_picker); - bottomSheetDialog1.setCancelable(true); - bottomSheetDialog1.setDismissWithAnimation(true); - - GridView colorGridView = (GridView) bottomSheetDialog1.findViewById(R.id.colorGridView); - - ArrayList shapes = new ArrayList<>(); - shapes.add(new Shape(R.drawable.ic_coffee)); - shapes.add(new Shape(R.drawable.ic_child_care)); - shapes.add(new Shape(R.drawable.ic_fitness_center)); - shapes.add(new Shape(R.drawable.ic_headphones)); - shapes.add(new Shape(R.drawable.ic_hotel)); - shapes.add(new Shape(R.drawable.ic_local_shipping)); - shapes.add(new Shape(R.drawable.ic_perm_phone_msg)); - shapes.add(new Shape(R.drawable.ic_phishing)); - shapes.add(new Shape(R.drawable.ic_work)); - shapes.add(new Shape(R.drawable.ic_work_outline)); - shapes.add(new Shape(R.drawable.ic_receipt_long)); - shapes.add(new Shape(R.drawable.ic_rocket_launch)); - shapes.add(new Shape(R.drawable.ic_school)); - shapes.add(new Shape(R.drawable.ic_shopping_basket)); - shapes.add(new Shape(R.drawable.ic_spa)); - shapes.add(new Shape(R.drawable.ic_square_foot)); - shapes.add(new Shape(R.drawable.ic_grade)); - - OpacityAdapter shapeAdapter = new OpacityAdapter(getContext(), 0, shapes); - Objects.requireNonNull(colorGridView).setAdapter(shapeAdapter); - - bottomSheetDialog1.show(); - - //Clicker - colorGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - opacityRes = shapes.get(position).getShapeRes(); - bottomSheetDialog1.dismiss(); - } - }); - } - }); - - //Done - Objects.requireNonNull(btnDone).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - String note = Objects.requireNonNull(tvTitle).getText().toString(); - String text = Objects.requireNonNull(tvText).getText().toString(); - -// SAVE - saveNote(note, text, opacityRes, color, view); - bottomSheetDialog.dismiss(); - } - }); - - bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { -// UPDATE - reloadRecyclerView(getContext(), getActivity()); - } - }); - } - }); - - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String s) { - return false; - } - - @Override - public boolean onQueryTextChange(String s) { - NoteAdapter noteAdapter = new NoteAdapter(getContext(), getActivity(), loadNotesWithCondition(s), 1); - recyclerViewNotes.setHasFixedSize(true); - recyclerViewNotes.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerViewNotes.setAdapter(noteAdapter); - return false; - } - }); - return view; - } - - public static List loadNotes(Context context) { - List notes = new ArrayList<>(); - -// Pinned notes - @SuppressLint("Recycle") Cursor cursor = sqLiteDatabaseNotes.query( - DatabaseConstants._NOTES_TABLE_NAME, // The table to query - null, // The array of columns to return (pass null to get all) - DatabaseConstants._IS_PINNED + " = ?", // The columns for the WHERE clause - new String[]{"1"}, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - null // The sort order - ); - - while (cursor.moveToNext()) { -// Read data - int id = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._ID)); -// int count = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._COUNT)); - int notePromoResId = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_PROMO)); - int isPinned = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_PINNED)); - int isLiked = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_LIKED)); - int colorRes = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_COLOR)); - String noteName = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_NAME)); - String noteText = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_TEXT)); - long addTime = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseConstants._ADD_NOTE_TIME)); - - Note note = new Note( - id, - 0, - notePromoResId, - isPinned, - isLiked, - colorRes, - noteName, - noteText, - addTime, - 0 - ); - notes.add(note); - } - cursor.close(); - -// Simple notes - @SuppressLint("Recycle") Cursor cursor1 = sqLiteDatabaseNotes.query( - DatabaseConstants._NOTES_TABLE_NAME, // The table to query - null, // The array of columns to return (pass null to get all) - DatabaseConstants._IS_PINNED + " = ?", // The columns for the WHERE clause - new String[]{"0"}, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - null // The sort order - ); - - while (cursor1.moveToNext()) { -// Read data - int id = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._ID)); -// int count = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._COUNT)); - int notePromoResId = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_PROMO)); - int isPinned = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_PINNED)); - int isLiked = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_LIKED)); - int colorRes = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_COLOR)); - String noteName = cursor1.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_NAME)); - String noteText = cursor1.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_TEXT)); - long addTime = cursor1.getLong(cursor.getColumnIndexOrThrow(DatabaseConstants._ADD_NOTE_TIME)); - - Note note = new Note( - id, - 0, - notePromoResId, - isPinned, - isLiked, - colorRes, - noteName, - noteText, - addTime, - 0 - ); - notes.add(note); - } - cursor1.close(); - - return notes; - } - - public static List loadNotesWithCondition(String condition) { - List notes = new ArrayList<>(); - -// Pinned notes - @SuppressLint("Recycle") Cursor cursor = sqLiteDatabaseNotes.query( - DatabaseConstants._NOTES_TABLE_NAME, // The table to query - null, // The array of columns to return (pass null to get all) - DatabaseConstants._IS_PINNED + " = ?", // The columns for the WHERE clause - new String[]{"1"}, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - null // The sort order - ); - - while (cursor.moveToNext()) { -// Read data - int id = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._ID)); -// int count = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._COUNT)); - int notePromoResId = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_PROMO)); - int isPinned = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_PINNED)); - int isLiked = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_LIKED)); - int colorRes = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_COLOR)); - String noteName = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_NAME)); - String noteText = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_TEXT)); - long addTime = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseConstants._ADD_NOTE_TIME)); - - Note note = new Note( - id, - 0, - notePromoResId, - isPinned, - isLiked, - colorRes, - noteName, - noteText, - addTime, - 0 - ); - notes.add(note); - } - cursor.close(); - -// Simple notes - @SuppressLint("Recycle") Cursor cursor1 = sqLiteDatabaseNotes.query( - DatabaseConstants._NOTES_TABLE_NAME, // The table to query - null, // The array of columns to return (pass null to get all) - DatabaseConstants._IS_PINNED + " = ?", // The columns for the WHERE clause - new String[]{"0"}, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - null // The sort order - ); - - while (cursor1.moveToNext()) { -// Read data - int id = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._ID)); -// int count = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._COUNT)); - int notePromoResId = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_PROMO)); - int isPinned = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_PINNED)); - int isLiked = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._IS_LIKED)); - int colorRes = cursor1.getInt(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_COLOR)); - String noteName = cursor1.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_NAME)); - String noteText = cursor1.getString(cursor.getColumnIndexOrThrow(DatabaseConstants._NOTE_TEXT)); - long addTime = cursor1.getLong(cursor.getColumnIndexOrThrow(DatabaseConstants._ADD_NOTE_TIME)); - - if (noteName.contains(condition) || noteText.contains(condition) || new SimpleDateFormat("dd.MM.yyyy HH.mm", Locale.getDefault()).format(new Date(addTime)).contains(condition)) { - Note note = new Note( - id, - 0, - notePromoResId, - isPinned, - isLiked, - colorRes, - noteName, - noteText, - addTime, - 0 - ); - notes.add(note); - } - } - cursor1.close(); - - return notes; - } - - public void saveNote(String name, String text, int or, int c, View view) { - if (name == null || name.isEmpty()) - name = ""; - if (text == null || text.isEmpty()) - text = ""; - - ContentValues contentValues = new ContentValues(); - contentValues.put(DatabaseConstants._NOTE_NAME, name); - contentValues.put(DatabaseConstants._NOTE_TEXT, text); - contentValues.put(DatabaseConstants._NOTE_PROMO, or); - contentValues.put(DatabaseConstants._NOTE_COLOR, c); - contentValues.put(DatabaseConstants._IS_LIKED, 0); - contentValues.put(DatabaseConstants._IS_PINNED, 0); - contentValues.put(DatabaseConstants._ADD_NOTE_TIME, System.currentTimeMillis()); - sqLiteDatabaseNotes.insert(DatabaseConstants._NOTES_TABLE_NAME, null, contentValues); - - Snackbar - .make(requireContext(), (ConstraintLayout) view.findViewById(R.id.layout), "Данные сохранены✅", Snackbar.LENGTH_SHORT) - .setTextColor(Color.parseColor("#000000")) - .setBackgroundTint(Color.WHITE) - .show(); - - reloadRecyclerView(getContext(), getActivity()); - } - - public static void saveNote(String name, String text, int or, int c, int isLiked) { - ContentValues contentValues = new ContentValues(); - contentValues.put(DatabaseConstants._NOTE_NAME, name); - contentValues.put(DatabaseConstants._NOTE_TEXT, text); - contentValues.put(DatabaseConstants._NOTE_PROMO, or); - contentValues.put(DatabaseConstants._NOTE_COLOR, c); - contentValues.put(DatabaseConstants._IS_LIKED, isLiked); - contentValues.put(DatabaseConstants._IS_PINNED, 0); - contentValues.put(DatabaseConstants._ADD_NOTE_TIME, System.currentTimeMillis()); - sqLiteDatabaseNotes.insert(DatabaseConstants._NOTES_TABLE_NAME, null, contentValues); - } - - public static void saveNote(String name, String text, int or, int c, int isLiked, int isPinned) { - ContentValues contentValues = new ContentValues(); - contentValues.put(DatabaseConstants._NOTE_NAME, name); - contentValues.put(DatabaseConstants._NOTE_TEXT, text); - contentValues.put(DatabaseConstants._NOTE_PROMO, or); - contentValues.put(DatabaseConstants._NOTE_COLOR, c); - contentValues.put(DatabaseConstants._IS_LIKED, isLiked); - contentValues.put(DatabaseConstants._IS_PINNED, isPinned); - contentValues.put(DatabaseConstants._ADD_NOTE_TIME, System.currentTimeMillis()); - sqLiteDatabaseNotes.insert(DatabaseConstants._NOTES_TABLE_NAME, null, contentValues); - } - - public static void reloadRecyclerView(Context context, Activity activity) { - recyclerViewNotes.setVisibility(View.GONE); - NoteAdapter noteAdapter = new NoteAdapter(context, activity, loadNotes(context), 1); - recyclerViewNotes.setHasFixedSize(true); - recyclerViewNotes.setLayoutManager(new LinearLayoutManager(context)); - recyclerViewNotes.setAdapter(noteAdapter); - recyclerViewNotes.setVisibility(View.VISIBLE); - isList = true; - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/plumsoftware/notebook/fragments/SearchFragment.java b/app/src/main/java/ru/plumsoftware/notebook/fragments/SearchFragment.java deleted file mode 100644 index 1075ff8..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/fragments/SearchFragment.java +++ /dev/null @@ -1,48 +0,0 @@ -package ru.plumsoftware.notebook.fragments; - -import android.os.Bundle; - -import androidx.fragment.app.Fragment; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import ru.plumsoftware.notebook.R; - -public class SearchFragment extends Fragment { - - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - private String mParam1; - private String mParam2; - - public SearchFragment() { - // Required empty public constructor - } - - public static SearchFragment newInstance(String param1, String param2) { - SearchFragment fragment = new SearchFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_search, container, false); - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/plumsoftware/notebook/manager/extra/ExtraNames.java b/app/src/main/java/ru/plumsoftware/notebook/manager/extra/ExtraNames.java new file mode 100644 index 0000000..7aea6a1 --- /dev/null +++ b/app/src/main/java/ru/plumsoftware/notebook/manager/extra/ExtraNames.java @@ -0,0 +1,11 @@ +package ru.plumsoftware.notebook.manager.extra; + +import kotlin.Pair; + +public class ExtraNames { + public static class LocalNotificationExtra { + public static String message = "message"; + public static String notificationChannelId = "notificationChannelId"; + public static Pair colorPair = new Pair<>("color", 0); + } +} diff --git a/app/src/main/java/ru/plumsoftware/notebook/manager/notification/LocalNotificationConstants.java b/app/src/main/java/ru/plumsoftware/notebook/manager/notification/LocalNotificationConstants.java new file mode 100644 index 0000000..e71ec8f --- /dev/null +++ b/app/src/main/java/ru/plumsoftware/notebook/manager/notification/LocalNotificationConstants.java @@ -0,0 +1,6 @@ +package ru.plumsoftware.notebook.manager.notification; + +public class LocalNotificationConstants { + public static String CHANNEL_ID = "ru.plumsoftware.notebook.notif_channel"; + public static final String GROUP_KEY = "ru.plumsoftware.notebook.group_key"; +} diff --git a/app/src/main/java/ru/plumsoftware/notebook/utilities/NotificationUtils.java b/app/src/main/java/ru/plumsoftware/notebook/manager/notification/NotificationManager.java similarity index 59% rename from app/src/main/java/ru/plumsoftware/notebook/utilities/NotificationUtils.java rename to app/src/main/java/ru/plumsoftware/notebook/manager/notification/NotificationManager.java index c6e8a19..c112ba2 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/utilities/NotificationUtils.java +++ b/app/src/main/java/ru/plumsoftware/notebook/manager/notification/NotificationManager.java @@ -1,8 +1,7 @@ -package ru.plumsoftware.notebook.utilities; +package ru.plumsoftware.notebook.manager.notification; import android.annotation.SuppressLint; import android.app.NotificationChannel; -import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -12,41 +11,40 @@ import androidx.core.app.NotificationManagerCompat; import java.util.Calendar; -import java.util.Random; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.activities.MainActivity; +import ru.plumsoftware.notebook.presentation.activities.MainActivity; -public class NotificationUtils { - - private static String CHANNEL_ID = "ru.plumsoftware.notebook.notif_channel"; // Уникальный идентификатор канала уведомлений - private static final String GROUP_KEY = "ru.plumsoftware.notebook.group_key"; // Идентификатор группы уведомлений +public class NotificationManager { @SuppressLint("MissingPermission") public static void createNotification(Context context, String title, String message, int color, String notificationChannelId) { - //Id канала уведомления - CHANNEL_ID = notificationChannelId; + LocalNotificationConstants.CHANNEL_ID = notificationChannelId; - // Создание интента для перехода при клике на уведомление Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); - // Создание канала уведомлений для Android 8.0 (Oreo) и выше + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "plumsoftware.notebook.notif_name_" + CHANNEL_ID; + CharSequence name = "plumsoftware.notebook.notif_name_" + LocalNotificationConstants.CHANNEL_ID; String description = "plumsoftware.notebook.notif_channel_description"; - int importance = NotificationManager.IMPORTANCE_HIGH; - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); + int importance = android.app.NotificationManager.IMPORTANCE_HIGH; + NotificationChannel channel = new NotificationChannel(LocalNotificationConstants.CHANNEL_ID, name, importance); channel.setDescription(description); channel.enableLights(true); channel.setLightColor(color); - NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + android.app.NotificationManager notificationManager = context.getSystemService(android.app.NotificationManager.class); notificationManager.createNotificationChannel(channel); } - // Создание уведомления - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + NotificationCompat.Builder builder = buildStandardNotification(context, title, message, pendingIntent, color); + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + notificationManager.notify(Calendar.getInstance().get(Calendar.MILLISECOND), builder.build()); + } + + private static NotificationCompat.Builder buildStandardNotification(Context context, String title, String message, PendingIntent pendingIntent, int color) { + return new NotificationCompat.Builder(context, LocalNotificationConstants.CHANNEL_ID) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(title) .setContentText(message) @@ -56,10 +54,6 @@ public static void createNotification(Context context, String title, String mess .setColorized(true) .setColor(color) .setStyle(new NotificationCompat.BigTextStyle()) - .setGroup(GROUP_KEY); - - // Отображение уведомления - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); - notificationManager.notify(Calendar.getInstance().get(Calendar.MILLISECOND), builder.build()); + .setGroup(LocalNotificationConstants.GROUP_KEY); } } diff --git a/app/src/main/java/ru/plumsoftware/notebook/utilities/UniqueIdGenerator.java b/app/src/main/java/ru/plumsoftware/notebook/manager/unique/UniqueIdGenerator.java similarity index 77% rename from app/src/main/java/ru/plumsoftware/notebook/utilities/UniqueIdGenerator.java rename to app/src/main/java/ru/plumsoftware/notebook/manager/unique/UniqueIdGenerator.java index 814556b..c1b4f62 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/utilities/UniqueIdGenerator.java +++ b/app/src/main/java/ru/plumsoftware/notebook/manager/unique/UniqueIdGenerator.java @@ -1,4 +1,6 @@ -package ru.plumsoftware.notebook.utilities; +package ru.plumsoftware.notebook.manager.unique; + +import androidx.annotation.NonNull; import java.util.HashSet; import java.util.Random; @@ -22,7 +24,7 @@ public static String generateUniqueId() { sb.append(getRandomCharacter(DIGITS, random)); sb.append(getRandomCharacter(UPPER_CASE_ALPHABET + LOWER_CASE_ALPHABET + DIGITS, random)); - if (i != 3) { // Добавляем "-" между каждым блоком + if (i != 3) { sb.append("-"); } } @@ -30,21 +32,21 @@ public static String generateUniqueId() { return sb.toString(); } + @NonNull public static String generateUniqueId_2() { Set generatedIds = new HashSet<>(); Random random = new Random(); StringBuilder idBuilder = new StringBuilder(ID_LENGTH); while (true) { - idBuilder.setLength(0); // Очищаем StringBuilder перед генерацией нового идентификатора + idBuilder.setLength(0); - // Генерируем символы и числа в идентификатор for (int i = 0; i < ID_LENGTH; i++) { char randomChar; if (random.nextBoolean()) { - randomChar = (char) (random.nextInt(26) + 'A'); // Заглавная буква + randomChar = (char) (random.nextInt(26) + 'A'); } else { - randomChar = (char) (random.nextInt(26) + 'a'); // Строчная буква + randomChar = (char) (random.nextInt(26) + 'a'); } idBuilder.append(randomChar); } @@ -56,7 +58,7 @@ public static String generateUniqueId_2() { } } - private static char getRandomCharacter(String characters, Random random) { + private static char getRandomCharacter(@NonNull String characters, @NonNull Random random) { int index = random.nextInt(characters.length()); return characters.charAt(index); } diff --git a/app/src/main/java/ru/plumsoftware/notebook/activities/AddNoteActivity.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/AddNoteActivity.java similarity index 91% rename from app/src/main/java/ru/plumsoftware/notebook/activities/AddNoteActivity.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/activities/AddNoteActivity.java index 70efbdb..3ef3691 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/activities/AddNoteActivity.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/AddNoteActivity.java @@ -1,11 +1,10 @@ -package ru.plumsoftware.notebook.activities; +package ru.plumsoftware.notebook.presentation.activities; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.cardview.widget.CardView; import androidx.core.app.ActivityCompat; - import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; @@ -31,7 +30,6 @@ import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; - import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.snackbar.Snackbar; import com.yandex.mobile.ads.common.AdError; @@ -43,28 +41,23 @@ import com.yandex.mobile.ads.interstitial.InterstitialAdEventListener; import com.yandex.mobile.ads.interstitial.InterstitialAdLoadListener; import com.yandex.mobile.ads.interstitial.InterstitialAdLoader; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; import java.util.Locale; import java.util.Objects; - -import ru.plumsoftware.notebook.dialogs.ProgressDialog; +import ru.plumsoftware.data.database.SQLiteDatabaseManager; +import ru.plumsoftware.data.model.database.DatabaseConstants; +import ru.plumsoftware.data.model.ui.Colors; +import ru.plumsoftware.data.model.ui.Note; +import ru.plumsoftware.data.model.ui.Shape; +import ru.plumsoftware.notebook.presentation.dialogs.ProgressDialog; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.adapters.ColorAdapter; -import ru.plumsoftware.notebook.adapters.GroupAdapter; -import ru.plumsoftware.notebook.adapters.OpacityAdapter; -import ru.plumsoftware.notebook.data.items.Colors; -import ru.plumsoftware.notebook.data.items.Group; -import ru.plumsoftware.notebook.data.items.Note; -import ru.plumsoftware.notebook.data.items.Shape; -import ru.plumsoftware.notebook.databases.DatabaseConstants; -import ru.plumsoftware.notebook.databases.SQLiteDatabaseManager; -import ru.plumsoftware.notebook.services.NotificationScheduler; -import ru.plumsoftware.notebook.utilities.UniqueIdGenerator; +import ru.plumsoftware.notebook.presentation.adapters.ColorAdapter; +import ru.plumsoftware.notebook.presentation.adapters.OpacityAdapter; +import ru.plumsoftware.notebook.services.scheduler.NotificationScheduler; +import ru.plumsoftware.notebook.manager.unique.UniqueIdGenerator; public class AddNoteActivity extends AppCompatActivity { @@ -236,24 +229,6 @@ public void onClick(View view) { setAlarmManager(noteTime, noteTitle, color, notificationChannelId); } } - - List groupList = GroupAdapter.addedGroups; - - for (int i = 0; i < groupList.size(); i++) { - String name = groupList.get(i).getName(); - - ContentValues contentValues = new ContentValues(); - contentValues.put(DatabaseConstants._GROUP_NAME, name); - contentValues.put(DatabaseConstants._NOTE_COLOR, color); - contentValues.put(DatabaseConstants._ADD_NOTE_TIME, noteTime); - contentValues.put(DatabaseConstants._ADD_GROUP_TIME, System.currentTimeMillis()); - sqLiteDatabaseNotes.update(DatabaseConstants._GROUPS_TABLE_NAME, contentValues, DatabaseConstants._GROUP_NAME + " = ?", new String[]{name}); -// try { -// NotepadActivity.reloadRecyclerView(AddNoteActivity.this, AddNoteActivity.this); -// } catch (Exception e) { -// e.printStackTrace(); -// } - } } }); diff --git a/app/src/main/java/ru/plumsoftware/notebook/activities/MainActivity.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/MainActivity.java similarity index 98% rename from app/src/main/java/ru/plumsoftware/notebook/activities/MainActivity.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/activities/MainActivity.java index c1aafa4..d5a015a 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/activities/MainActivity.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/MainActivity.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.activities; +package ru.plumsoftware.notebook.presentation.activities; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -7,7 +7,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; - import android.annotation.SuppressLint; import android.app.Activity; import android.content.ContentValues; @@ -23,7 +22,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.SearchView; - import com.google.android.material.snackbar.Snackbar; import com.yandex.mobile.ads.appopenad.AppOpenAd; import com.yandex.mobile.ads.appopenad.AppOpenAdEventListener; @@ -34,20 +32,18 @@ import com.yandex.mobile.ads.common.AdRequestError; import com.yandex.mobile.ads.common.ImpressionData; import com.yandex.mobile.ads.common.MobileAds; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; +import ru.plumsoftware.data.database.SQLiteDatabaseManager; +import ru.plumsoftware.data.model.database.DatabaseConstants; +import ru.plumsoftware.data.model.ui.Note; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.adapters.NoteAdapter; -import ru.plumsoftware.notebook.data.items.Group; -import ru.plumsoftware.notebook.data.items.Note; -import ru.plumsoftware.notebook.databases.DatabaseConstants; -import ru.plumsoftware.notebook.databases.SQLiteDatabaseManager; -import ru.plumsoftware.notebook.dialogs.ProgressDialog; +import ru.plumsoftware.notebook.presentation.adapters.NoteAdapter; +import ru.plumsoftware.notebook.presentation.dialogs.ProgressDialog; public class MainActivity extends AppCompatActivity { public static SQLiteDatabase sqLiteDatabaseNotes; diff --git a/app/src/main/java/ru/plumsoftware/notebook/activities/NotepadActivity.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/NotepadActivity.java similarity index 94% rename from app/src/main/java/ru/plumsoftware/notebook/activities/NotepadActivity.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/activities/NotepadActivity.java index e92ef98..5e35c52 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/activities/NotepadActivity.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/activities/NotepadActivity.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.activities; +package ru.plumsoftware.notebook.presentation.activities; import androidx.appcompat.app.AppCompatActivity; import androidx.cardview.widget.CardView; @@ -6,7 +6,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; - import android.annotation.SuppressLint; import android.app.Activity; import android.content.ContentValues; @@ -25,29 +24,24 @@ import android.widget.ImageView; import android.widget.SearchView; import android.widget.Toast; - import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.snackbar.Snackbar; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Objects; - -import ru.plumsoftware.notebook.dialogs.ProgressDialog; +import ru.plumsoftware.data.database.SQLiteDatabaseManager; +import ru.plumsoftware.data.model.database.DatabaseConstants; +import ru.plumsoftware.data.model.ui.Colors; +import ru.plumsoftware.data.model.ui.Note; +import ru.plumsoftware.data.model.ui.Shape; +import ru.plumsoftware.notebook.presentation.dialogs.ProgressDialog; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.adapters.ColorAdapter; -import ru.plumsoftware.notebook.adapters.GroupAdapter; -import ru.plumsoftware.notebook.adapters.NoteAdapter; -import ru.plumsoftware.notebook.adapters.OpacityAdapter; -import ru.plumsoftware.notebook.data.items.Colors; -import ru.plumsoftware.notebook.data.items.Group; -import ru.plumsoftware.notebook.data.items.Note; -import ru.plumsoftware.notebook.data.items.Shape; -import ru.plumsoftware.notebook.databases.DatabaseConstants; -import ru.plumsoftware.notebook.databases.SQLiteDatabaseManager; +import ru.plumsoftware.notebook.presentation.adapters.ColorAdapter; +import ru.plumsoftware.notebook.presentation.adapters.NoteAdapter; +import ru.plumsoftware.notebook.presentation.adapters.OpacityAdapter; public class NotepadActivity extends AppCompatActivity { public static SQLiteDatabase sqLiteDatabaseNotes; @@ -79,7 +73,6 @@ protected void onCreate(Bundle savedInstanceState) { SQLiteDatabaseManager sqLiteDatabaseManager = new SQLiteDatabaseManager(context); sqLiteDatabaseNotes = sqLiteDatabaseManager.getWritableDatabase(); List notes = new ArrayList<>(); - List groups = new ArrayList<>(); String groupName; @@ -329,24 +322,6 @@ public void onClick(View v) { // SAVE long time = System.currentTimeMillis(); saveNote(note, text, opacityRes, color, time); - - List groupList = GroupAdapter.addedGroups; - - for (int i = 0; i < groupList.size(); i++) { - String name = groupList.get(i).getName(); - - ContentValues contentValues = new ContentValues(); - contentValues.put(DatabaseConstants._GROUP_NAME, name); - contentValues.put(DatabaseConstants._NOTE_COLOR, color); - contentValues.put(DatabaseConstants._ADD_NOTE_TIME, time); - contentValues.put(DatabaseConstants._ADD_GROUP_TIME, System.currentTimeMillis()); - sqLiteDatabaseNotes.update(DatabaseConstants._GROUPS_TABLE_NAME, contentValues, DatabaseConstants._GROUP_NAME + " = ?", new String[]{name}); - try { - NotepadActivity.reloadRecyclerView(context, NotepadActivity.this); - } catch (Exception e) { - e.printStackTrace(); - } - } progressDialog.dismiss(); bottomSheetDialog.dismiss(); //sqLiteDatabaseNotes.close(); diff --git a/app/src/main/java/ru/plumsoftware/notebook/adapters/ColorAdapter.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/ColorAdapter.java similarity index 89% rename from app/src/main/java/ru/plumsoftware/notebook/adapters/ColorAdapter.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/ColorAdapter.java index 1ff4412..84571f2 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/adapters/ColorAdapter.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/ColorAdapter.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.adapters; +package ru.plumsoftware.notebook.presentation.adapters; import android.annotation.SuppressLint; import android.content.Context; @@ -13,8 +13,8 @@ import java.util.List; +import ru.plumsoftware.data.model.ui.Colors; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.data.items.Colors; public class ColorAdapter extends ArrayAdapter { public ColorAdapter(@NonNull Context context, int resource, @NonNull List objects) { @@ -29,6 +29,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup convertView = LayoutInflater.from(getContext()).inflate(R.layout.color_layout, parent, false); Colors colors = getItem(position); + assert colors != null; int colorRes = colors.getColorRes(); CardView cardView = (CardView) convertView.findViewById(R.id.colorView); diff --git a/app/src/main/java/ru/plumsoftware/notebook/adapters/NoteAdapter.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/NoteAdapter.java similarity index 98% rename from app/src/main/java/ru/plumsoftware/notebook/adapters/NoteAdapter.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/NoteAdapter.java index 66bb0fe..56bcfcc 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/adapters/NoteAdapter.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/NoteAdapter.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.adapters; +package ru.plumsoftware.notebook.presentation.adapters; import android.annotation.SuppressLint; import android.app.Activity; @@ -44,13 +44,13 @@ import java.util.List; import java.util.Locale; -import ru.plumsoftware.notebook.activities.AddNoteActivity; -import ru.plumsoftware.notebook.activities.MainActivity; -import ru.plumsoftware.notebook.dialogs.ProgressDialog; +import ru.plumsoftware.data.database.SQLiteDatabaseManager; +import ru.plumsoftware.data.model.database.DatabaseConstants; +import ru.plumsoftware.data.model.ui.Note; +import ru.plumsoftware.notebook.presentation.activities.AddNoteActivity; +import ru.plumsoftware.notebook.presentation.activities.MainActivity; +import ru.plumsoftware.notebook.presentation.dialogs.ProgressDialog; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.data.items.Note; -import ru.plumsoftware.notebook.databases.DatabaseConstants; -import ru.plumsoftware.notebook.databases.SQLiteDatabaseManager; public class NoteAdapter extends RecyclerView.Adapter { private Context context; diff --git a/app/src/main/java/ru/plumsoftware/notebook/adapters/OpacityAdapter.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/OpacityAdapter.java similarity index 88% rename from app/src/main/java/ru/plumsoftware/notebook/adapters/OpacityAdapter.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/OpacityAdapter.java index c5c9478..70b4f8a 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/adapters/OpacityAdapter.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/adapters/OpacityAdapter.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.adapters; +package ru.plumsoftware.notebook.presentation.adapters; import android.content.Context; import android.view.LayoutInflater; @@ -6,16 +6,14 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; - import java.util.List; - +import ru.plumsoftware.data.model.ui.Shape; import ru.plumsoftware.notebook.R; -import ru.plumsoftware.notebook.data.items.Shape; public class OpacityAdapter extends ArrayAdapter { + @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { Shape shape = getItem(position); @@ -24,6 +22,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup convertView = LayoutInflater.from(getContext()).inflate(R.layout.color_layout, parent, false); } + assert shape != null; int shapeRes = shape.getShapeRes(); ImageView imageView = (ImageView) convertView.findViewById(R.id.shapeView); @@ -34,6 +33,5 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup public OpacityAdapter(@NonNull Context context, int resource, @NonNull List objects) { super(context, resource, objects); - } } diff --git a/app/src/main/java/ru/plumsoftware/notebook/dialogs/ProgressDialog.java b/app/src/main/java/ru/plumsoftware/notebook/presentation/dialogs/ProgressDialog.java similarity index 95% rename from app/src/main/java/ru/plumsoftware/notebook/dialogs/ProgressDialog.java rename to app/src/main/java/ru/plumsoftware/notebook/presentation/dialogs/ProgressDialog.java index 220debc..d86cdf3 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/dialogs/ProgressDialog.java +++ b/app/src/main/java/ru/plumsoftware/notebook/presentation/dialogs/ProgressDialog.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.dialogs; +package ru.plumsoftware.notebook.presentation.dialogs; import android.annotation.SuppressLint; import android.app.Dialog; diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/MyFirebaseMessagingService.java b/app/src/main/java/ru/plumsoftware/notebook/services/MyFirebaseMessagingService.java deleted file mode 100644 index 25541fb..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/services/MyFirebaseMessagingService.java +++ /dev/null @@ -1,47 +0,0 @@ -package ru.plumsoftware.notebook.services; - -import android.annotation.SuppressLint; -import android.app.Service; -import android.content.Intent; -import android.os.IBinder; -import android.util.Log; - -import androidx.annotation.Nullable; - -import com.google.firebase.messaging.FirebaseMessagingService; -import com.google.firebase.messaging.RemoteMessage; - -@SuppressLint("MissingFirebaseInstanceTokenRefresh") -public class MyFirebaseMessagingService extends FirebaseMessagingService { - private static final String TAG = "TAG_1"; - @Override - public void onMessageReceived(RemoteMessage remoteMessage) { - // ... - - // TODO(developer): Handle FCM messages here. - // Not getting messages here? See why this may be: https://goo.gl/39bRNJ - Log.d(TAG, "From: " + remoteMessage.getFrom()); - - // Check if message contains a data payload. - if (remoteMessage.getData().size() > 0) { - Log.d(TAG, "Message data payload: " + remoteMessage.getData()); - - if (/* Check if data needs to be processed by long running job */ true) { - // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher. - //scheduleJob(); - } else { - // Handle message within 10 seconds - //handleNow(); - } - - } - - // Check if message contains a notification payload. - if (remoteMessage.getNotification() != null) { - Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); - } - - // Also if you intend on generating your own notifications as a result of a received FCM - // message, here is where that should be initiated. See sendNotification method below. - } -} diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/NotificationReceiver.java b/app/src/main/java/ru/plumsoftware/notebook/services/NotificationReceiver.java deleted file mode 100644 index 1139704..0000000 --- a/app/src/main/java/ru/plumsoftware/notebook/services/NotificationReceiver.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.plumsoftware.notebook.services; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import ru.plumsoftware.notebook.utilities.NotificationUtils; - -public class NotificationReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - // Получение сообщения из интента - String message = intent.getStringExtra("message"); - String notificationChannelId = intent.getStringExtra("notificationChannelId"); - int color = intent.getIntExtra("color", 0); - - // Показ уведомления - NotificationUtils.createNotification(context, "\uD83D\uDD14 Напоминание о событии ", message, color, notificationChannelId); - } -} diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/push/MyFirebaseMessagingService.java b/app/src/main/java/ru/plumsoftware/notebook/services/push/MyFirebaseMessagingService.java new file mode 100644 index 0000000..5e9796a --- /dev/null +++ b/app/src/main/java/ru/plumsoftware/notebook/services/push/MyFirebaseMessagingService.java @@ -0,0 +1,22 @@ +package ru.plumsoftware.notebook.services.push; + +import android.annotation.SuppressLint; +import android.util.Log; + +import com.google.firebase.messaging.FirebaseMessagingService; +import com.google.firebase.messaging.RemoteMessage; + +@SuppressLint("MissingFirebaseInstanceTokenRefresh") +public class MyFirebaseMessagingService extends FirebaseMessagingService { + private static final String TAG = "TAG_1"; + @Override + public void onMessageReceived(RemoteMessage remoteMessage) { + Log.d(TAG, "From: " + remoteMessage.getFrom()); + if (!remoteMessage.getData().isEmpty()) { + Log.d(TAG, "Message data payload: " + remoteMessage.getData()); + } + if (remoteMessage.getNotification() != null) { + Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); + } + } +} diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/MyRuStoreMessagingService.java b/app/src/main/java/ru/plumsoftware/notebook/services/push/MyRuStoreMessagingService.java similarity index 85% rename from app/src/main/java/ru/plumsoftware/notebook/services/MyRuStoreMessagingService.java rename to app/src/main/java/ru/plumsoftware/notebook/services/push/MyRuStoreMessagingService.java index f7dade2..c9b3a44 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/services/MyRuStoreMessagingService.java +++ b/app/src/main/java/ru/plumsoftware/notebook/services/push/MyRuStoreMessagingService.java @@ -1,4 +1,4 @@ -package ru.plumsoftware.notebook.services; +package ru.plumsoftware.notebook.services.push; import android.app.Service; import android.content.Intent; diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/receive/NotificationReceiver.java b/app/src/main/java/ru/plumsoftware/notebook/services/receive/NotificationReceiver.java new file mode 100644 index 0000000..1227d43 --- /dev/null +++ b/app/src/main/java/ru/plumsoftware/notebook/services/receive/NotificationReceiver.java @@ -0,0 +1,21 @@ +package ru.plumsoftware.notebook.services.receive; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import androidx.annotation.NonNull; + +import ru.plumsoftware.notebook.manager.extra.ExtraNames; +import ru.plumsoftware.notebook.manager.notification.NotificationManager; + +public class NotificationReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, @NonNull Intent intent) { + String message = intent.getStringExtra(ExtraNames.LocalNotificationExtra.message); + String notificationChannelId = intent.getStringExtra(ExtraNames.LocalNotificationExtra.notificationChannelId); + int color = intent.getIntExtra(ExtraNames.LocalNotificationExtra.colorPair.getFirst(), ExtraNames.LocalNotificationExtra.colorPair.getSecond()); + + NotificationManager.createNotification(context, "\uD83D\uDD14 Напоминание о событии ", message, color, notificationChannelId); + } +} diff --git a/app/src/main/java/ru/plumsoftware/notebook/services/NotificationScheduler.java b/app/src/main/java/ru/plumsoftware/notebook/services/scheduler/NotificationScheduler.java similarity index 90% rename from app/src/main/java/ru/plumsoftware/notebook/services/NotificationScheduler.java rename to app/src/main/java/ru/plumsoftware/notebook/services/scheduler/NotificationScheduler.java index 21fa653..f2df9a2 100644 --- a/app/src/main/java/ru/plumsoftware/notebook/services/NotificationScheduler.java +++ b/app/src/main/java/ru/plumsoftware/notebook/services/scheduler/NotificationScheduler.java @@ -1,10 +1,12 @@ -package ru.plumsoftware.notebook.services; +package ru.plumsoftware.notebook.services.scheduler; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import ru.plumsoftware.notebook.services.receive.NotificationReceiver; + public class NotificationScheduler { public static void scheduleNotification(Context context, long timeInMillis, String message, int color, String notificationChannelId) { // Создание намерения для запуска BroadcastReceiver diff --git a/app/src/main/res/layout/activity_add_note.xml b/app/src/main/res/layout/activity_add_note.xml index 3afc8dc..e3bf636 100644 --- a/app/src/main/res/layout/activity_add_note.xml +++ b/app/src/main/res/layout/activity_add_note.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context=".activities.AddNoteActivity"> + tools:context=".presentation.activities.AddNoteActivity"> + tools:context=".presentation.activities.MainActivity"> + tools:context=".presentation.activities.NotepadActivity"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_notepad.xml b/app/src/main/res/layout/fragment_notepad.xml deleted file mode 100644 index b28612d..0000000 --- a/app/src/main/res/layout/fragment_notepad.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml deleted file mode 100644 index df3265b..0000000 --- a/app/src/main/res/layout/fragment_search.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/group_item_layout.xml b/app/src/main/res/layout/group_item_layout.xml deleted file mode 100644 index 00c5eac..0000000 --- a/app/src/main/res/layout/group_item_layout.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/main_menu_layout.xml b/app/src/main/res/layout/main_menu_layout.xml deleted file mode 100644 index 61fda0d..0000000 --- a/app/src/main/res/layout/main_menu_layout.xml +++ /dev/null @@ -1,538 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml-v25/shortcuts.xml b/app/src/main/res/xml-v25/shortcuts.xml index 9608625..95e25c2 100644 --- a/app/src/main/res/xml-v25/shortcuts.xml +++ b/app/src/main/res/xml-v25/shortcuts.xml @@ -10,7 +10,7 @@ + android:targetClass="ru.plumsoftware.notebook.presentation.activities.AddNoteActivity" /> diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml index 2116f7c..1a586ed 100644 --- a/app/src/main/res/xml/shortcuts.xml +++ b/app/src/main/res/xml/shortcuts.xml @@ -12,7 +12,7 @@ + android:targetClass="ru.plumsoftware.notebook.presentation.activities.AddNoteActivity" /> diff --git a/settings.gradle b/settings.gradle index eb8f561..bf8a1d8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,3 +17,5 @@ dependencyResolutionManagement { } rootProject.name = "Блокнот" include ':app' +include ':app-domain' +include ':app-data'