Skip to content

Commit

Permalink
Архитектура
Browse files Browse the repository at this point in the history
[+] Добавил data,domain и presentation слои.
[+] Перенёс в эти сло часть логики.
[~] Подчистил код: удалил ненужные активити и фрагменты.
  • Loading branch information
plumsoftware committed Sep 8, 2024
1 parent 81fcc82 commit f6f0261
Show file tree
Hide file tree
Showing 50 changed files with 296 additions and 2,063 deletions.
1 change: 1 addition & 0 deletions app-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app-data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Empty file added app-data/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions app-data/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}
4 changes: 4 additions & 0 deletions app-data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.plumsoftware.notebook.databases;
package ru.plumsoftware.data.model.database;

import android.provider.BaseColumns;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -355,11 +357,15 @@ public void writeToParcel(Parcel dest, int flags) {
}

public static final Creator<Note> CREATOR = new Creator<Note>() {
@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];
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
17 changes: 17 additions & 0 deletions app-data/src/test/java/ru/plumsoftware/data/ExampleUnitTest.java
Original file line number Diff line number Diff line change
@@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
1 change: 1 addition & 0 deletions app-domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
8 changes: 8 additions & 0 deletions app-domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("java-library")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
4 changes: 4 additions & 0 deletions app-domain/src/main/java/ru/plumsoftware/domain/MyClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ru.plumsoftware.domain;

public class MyClass {
}
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ dependencies {

//Analytics
implementation 'com.google.firebase:firebase-analytics:22.1.0'

//Modules
implementation project(':app-domain')
implementation project(':app-data')
}
25 changes: 10 additions & 15 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
Expand All @@ -20,24 +21,17 @@
android:supportsRtl="true"
android:theme="@style/Theme.Блокнот">
<activity
android:name=".activities.AddNoteActivity"
android:name=".presentation.activities.AddNoteActivity"
android:exported="false" />
<activity
android:name=".activities.NotepadActivity"
android:name=".presentation.activities.NotepadActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activities.MainMenuActivity"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".activities.MainActivity"
android:name=".presentation.activities.MainActivity"
android:exported="true"
android:hardwareAccelerated="true">
<intent-filter>
Expand All @@ -46,12 +40,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data android:name="android.app.shortcuts"
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<service
android:name=".services.MyRuStoreMessagingService"
android:name=".services.push.MyRuStoreMessagingService"
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
Expand All @@ -60,15 +55,15 @@
</service>

<service
android:name=".services.MyFirebaseMessagingService"
android:name=".services.push.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<receiver
android:name=".services.NotificationReceiver"
android:name=".services.receive.NotificationReceiver"
android:enabled="true"
android:exported="true" />

Expand Down
Loading

0 comments on commit f6f0261

Please sign in to comment.