Skip to content

Commit

Permalink
Merge pull request #3 from QiubyZ/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
QiubyZ authored Oct 8, 2024
2 parents 868b276 + bc24a14 commit ecb8740
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jobs:
with:
gradle_cmd: 'assembleDebug' # this is will write apk filename /app-release-unsigned.apk
tag: 'Production'
body_release: 'Aplikasi versi produksi dirilis.'
body_release: |
"* add direct input of keys and values
example:
t:test
"
file_output: './app/build/outputs/apk/debug/app-debug.apk'


Expand Down
5 changes: 5 additions & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/8.10/transforms/7c392bbeafcdeb9af33a42416f56b306/transformed/viewbinding-8.1.0-api.jar"/>
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/8.10/transforms/8490cc7984e3490f6c117f6851284e1f/transformed/viewpager-1.0.0-api.jar"/>
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/8.10/transforms/44a6f23cfde3f7ad4b602fd1a40d2275/transformed/viewpager2-1.0.0-api.jar"/>
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/modules-2/files-2.1/androidx.work/work-runtime/2.9.1/82cdda504d93e6f71464e4d2a74961e0b0ac709f/work-runtime-2.9.1.jar"/>
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/modules-2/files-2.1"/>
<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/modules-2/files-2.1/androidx.concurrent/concurrent-futures/1.2.0/6a1dfd69226e148898410721f4b14315343d1429/concurrent-futures-1.2.0.jar"/>

<classpathentry kind="lib" path="/data/data/com.termux/files/home/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/33.3.1-android/36162b3b4e9df67dae90db62a2c54616ca42c1bd/guava-33.3.1-android.jar"/>
<classpathentry kind="lib" path="."/>
</classpath>
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ android {
useSupportLibrary true
}
}

lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled true
Expand All @@ -37,7 +39,11 @@ android {

}

dependencies {
dependencies {
implementation "androidx.concurrent:concurrent-futures:1.2.0"
implementation("com.google.guava:guava:33.3.1-android")
implementation ('org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.1')
implementation("androidx.work:work-runtime:2.9.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.9.0")
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:requestLegacyExternalStorage="true"
Expand Down
50 changes: 49 additions & 1 deletion app/src/main/java/qz/userdictionary/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package qz.userdictionary;

import android.app.AlertDialog;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.provider.UserDictionary;
import android.widget.ScrollView;
import android.widget.Toast;
import qz.userdictionary.ViewModel.Dialogs;

import android.text.Editable;
import android.text.TextWatcher;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.ArrayList;
import qz.userdictionary.Model.TextItems;
import qz.userdictionary.Model.UserDictionaryHelper;
import qz.userdictionary.Service.AddItemOnService;
import qz.userdictionary.ViewModel.mAdpView;
import qz.userdictionary.databinding.ActivityMainBinding;
import androidx.work.*;

public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
Expand All @@ -32,6 +36,8 @@ public class MainActivity extends AppCompatActivity {
int MAX_LENGT = 101;
public static String WORD_KEYS = ":";

public static String WORD_KEYS = ":";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -41,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {

// set content view to binding's root
setContentView(binding.getRoot());
createNotificationChannel();

if (getIntent() != null) {
String words = getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT);
Expand All @@ -49,6 +56,32 @@ protected void onCreate(Bundle savedInstanceState) {
int firstColonIndex = words.indexOf(":");
String key1 = words.substring(0, firstColonIndex);
String key2 = words.substring(firstColonIndex + 1);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Data.Builder dataBuilder = new Data.Builder();
dataBuilder.putString("key1", key1);
dataBuilder.putString("key2", key2);
Data data = dataBuilder.build();
OneTimeWorkRequest myWorkRequest = new OneTimeWorkRequest.Builder(AddItemOnService.class)
.setInputData(data).build();
WorkManager.getInstance(getApplicationContext()).enqueue(myWorkRequest);

} else {
pesan(String.format("Add keys %s:%s ", key1, key2));
new Thread(new Runnable() {
@Override
public void run() {
new UserDictionaryHelper(binding.getRoot().getContext()).add(
new TextItems(
key2,
key1,
"250",
String.valueOf(UserDictionary.Words.LOCALE_TYPE_ALL)));
}
}).start();

}

pesan(String.format("Add keys %s dan %s ", key1, key2));
new Thread(new Runnable() {
@Override
Expand All @@ -61,6 +94,7 @@ public void run() {
String.valueOf(UserDictionary.Words.LOCALE_TYPE_ALL)));
}
}).start();

finish();

} else {
Expand Down Expand Up @@ -160,6 +194,20 @@ public void afterTextChanged(Editable arg0) {
});
}

private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel Name"; // Nama yang ditampilkan ke pengguna
String description = "Channel Description"; // Deskripsi channel
int importance = NotificationManager.IMPORTANCE_DEFAULT; // Atur level pentingnya
NotificationChannel channel = new NotificationChannel("channel_id", name, importance);
channel.setDescription(description);

// Registrasi channel dengan sistem
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}

String getStringSource(int s) {
return getResources().getString(s);
}
Expand Down
48 changes: 48 additions & 0 deletions app/src/main/java/qz/userdictionary/Service/AddItemOnService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package qz.userdictionary.Service;

import android.content.Context;
import android.provider.UserDictionary;
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import qz.userdictionary.Model.TextItems;
import qz.userdictionary.Model.UserDictionaryHelper;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

/**
* AddItemOnService
*/
public class AddItemOnService extends Worker {
public AddItemOnService(@NonNull Context ctx, @NonNull WorkerParameters workerParams) {
super(ctx, workerParams);

}

@NonNull
@Override
public Result doWork() {
String key1 = getInputData().getString("key1");
String key2 = getInputData().getString("key2");
new UserDictionaryHelper(getApplicationContext())
.add(
new TextItems(
key2,
key1,
"250",
String.valueOf(UserDictionary.Words.LOCALE_TYPE_ALL)));
showSuccessNotification("QZ UserDic", String.format("%s : %s", key1, key2));
return Result.success();
}

private void showSuccessNotification(String title, String message) {
int notificationId = 1;
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), "channel_id") // Anda
.setSmallIcon(android.R.drawable.ic_notification_overlay)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
notificationManager.notify(notificationId, builder.build());
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/qz/userdictionary/Service/testing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package qz.userdictionary.Service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

/**
* testing
*/
public class testing extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
8 changes: 2 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx512m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx1000m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
Expand All @@ -21,7 +21,3 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true

#This for AndroidIde, if you have no problem with the new aapt2 by google, please remove it below
#I am using build tools 34.0.4
#android.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2

0 comments on commit ecb8740

Please sign in to comment.