GUI stuff
This commit is contained in:
parent
38a9fd010f
commit
6cc406b56d
@ -69,6 +69,7 @@ dependencies {
|
|||||||
implementation 'io.reactivex.rxjava3:rxjava:3.1.5'
|
implementation 'io.reactivex.rxjava3:rxjava:3.1.5'
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.34'
|
compileOnly 'org.projectlombok:lombok:1.18.34'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
annotationProcessor 'org.projectlombok:lombok:1.18.34'
|
||||||
|
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
|
||||||
annotationProcessor libs.room.compiler
|
annotationProcessor libs.room.compiler
|
||||||
testImplementation libs.junit
|
testImplementation libs.junit
|
||||||
androidTestImplementation libs.ext.junit
|
androidTestImplementation libs.ext.junit
|
||||||
|
@ -39,11 +39,16 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
|
public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener {
|
||||||
private static final String TAG = MainActivity.class.getSimpleName();
|
private static final String TAG = MainActivity.class.getSimpleName();
|
||||||
|
|
||||||
private MainActivityController controller;
|
private MainActivityController controller;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private LinearLayout cfg_list;
|
||||||
|
|
||||||
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
|
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
|
||||||
new ActivityResultContracts.StartActivityForResult(),
|
new ActivityResultContracts.StartActivityForResult(),
|
||||||
result -> {
|
result -> {
|
||||||
@ -53,7 +58,7 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||||||
String raw_data = Util.readTextFromUri(this, data.getData());
|
String raw_data = Util.readTextFromUri(this, data.getData());
|
||||||
String name = Util.getFilenameFromUri(this, data.getData());
|
String name = Util.getFilenameFromUri(this, data.getData());
|
||||||
String b32 = Base32.builder().get().encodeToString(raw_data.getBytes(StandardCharsets.UTF_8));
|
String b32 = Base32.builder().get().encodeToString(raw_data.getBytes(StandardCharsets.UTF_8));
|
||||||
db.userDao().insertAll(new Config(name, b32));
|
this.controller.insertNewConfig(name, b32);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, e.getMessage());
|
Log.e(TAG, e.getMessage());
|
||||||
}
|
}
|
||||||
@ -75,12 +80,12 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||||||
|
|
||||||
ControllerManager.putController(new MainActivityController());
|
ControllerManager.putController(new MainActivityController());
|
||||||
this.controller = (MainActivityController) ControllerManager.getController(ControllerId.MainActivityController);
|
this.controller = (MainActivityController) ControllerManager.getController(ControllerId.MainActivityController);
|
||||||
|
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
|
this.cfg_list = (LinearLayout) findViewById(R.id.config_list);
|
||||||
|
|
||||||
this.controller.onCreateGUI(this);
|
this.controller.onCreateGUI(this);
|
||||||
|
|
||||||
@ -90,27 +95,6 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||||||
popup.getMenuInflater().inflate(R.menu.mm, popup.getMenu());
|
popup.getMenuInflater().inflate(R.menu.mm, popup.getMenu());
|
||||||
popup.show();
|
popup.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
LinearLayout cfg_list = (LinearLayout) findViewById(R.id.config_list);
|
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
|
||||||
Iterator<Config> iter = db.userDao().getAll().iterator();
|
|
||||||
while( iter.hasNext() ) {
|
|
||||||
Config config = iter.next();
|
|
||||||
View cfg_instance = inflater.inflate(R.layout.single_config, cfg_list, false);
|
|
||||||
TextView view_name = (TextView) cfg_instance.findViewById(R.id.config_name);
|
|
||||||
SwitchMaterial view_switch = (SwitchMaterial) cfg_instance.findViewById(R.id.config_switch);
|
|
||||||
//view_switch.setUseMaterialThemeColors(true);
|
|
||||||
view_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
|
||||||
Log.i(TAG, "onCheckedChanged " + b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
view_name.setText(config.title);
|
|
||||||
|
|
||||||
if( iter.hasNext() ) inflater.inflate(R.layout.single_divider, cfg_list, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,14 +1,33 @@
|
|||||||
package com.alterdekim.fridaapp.controller;
|
package com.alterdekim.fridaapp.controller;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.room.Room;
|
import androidx.room.Room;
|
||||||
|
|
||||||
|
import com.alterdekim.fridaapp.R;
|
||||||
|
import com.alterdekim.fridaapp.activity.MainActivity;
|
||||||
import com.alterdekim.fridaapp.room.AppDatabase;
|
import com.alterdekim.fridaapp.room.AppDatabase;
|
||||||
|
import com.alterdekim.fridaapp.room.Config;
|
||||||
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.rxjava3.functions.Action;
|
||||||
|
import io.reactivex.rxjava3.functions.Consumer;
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
|
|
||||||
public class MainActivityController implements IController {
|
public class MainActivityController implements IController {
|
||||||
|
|
||||||
|
private static final String TAG = MainActivityController.class.getSimpleName();
|
||||||
|
|
||||||
private AppDatabase db;
|
private AppDatabase db;
|
||||||
|
|
||||||
|
private MainActivity mainActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ControllerId getControllerId() {
|
public ControllerId getControllerId() {
|
||||||
return ControllerId.MainActivityController;
|
return ControllerId.MainActivityController;
|
||||||
@ -17,5 +36,35 @@ public class MainActivityController implements IController {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateGUI(AppCompatActivity activity) {
|
public void onCreateGUI(AppCompatActivity activity) {
|
||||||
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "def-db").build();
|
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "def-db").build();
|
||||||
|
this.mainActivity = (MainActivity) activity;
|
||||||
|
this.initConfigListGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initConfigListGUI() {
|
||||||
|
LayoutInflater inflater = this.mainActivity.getLayoutInflater();
|
||||||
|
this.mainActivity.getCfg_list().removeAllViews();
|
||||||
|
this.db.userDao().getAll()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext(config -> {
|
||||||
|
View cfg_instance = inflater.inflate(R.layout.single_config, this.mainActivity.getCfg_list(), false);
|
||||||
|
this.mainActivity.getCfg_list().addView(cfg_instance);
|
||||||
|
TextView view_name = (TextView) cfg_instance.findViewById(R.id.config_name);
|
||||||
|
SwitchMaterial view_switch = (SwitchMaterial) cfg_instance.findViewById(R.id.config_switch);
|
||||||
|
view_switch.setUseMaterialThemeColors(true);
|
||||||
|
view_switch.setOnCheckedChangeListener((compoundButton, b) -> Log.i(TAG, "onCheckedChanged " + b));
|
||||||
|
view_name.setText(config.title);
|
||||||
|
})
|
||||||
|
.doAfterNext(config -> inflater.inflate(R.layout.single_divider, this.mainActivity.getCfg_list(), false))
|
||||||
|
.subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertNewConfig(String name, String b32) {
|
||||||
|
db.userDao().insertAll(new Config(name, b32))
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnError(throwable -> Toast.makeText(MainActivityController.this.mainActivity, R.string.config_adding_error, Toast.LENGTH_LONG).show())
|
||||||
|
.doOnComplete(this::initConfigListGUI)
|
||||||
|
.subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Config {
|
public class Config {
|
||||||
@PrimaryKey
|
@PrimaryKey(autoGenerate = true)
|
||||||
public int uid;
|
public int uid;
|
||||||
|
|
||||||
@ColumnInfo(name = "title")
|
@ColumnInfo(name = "title")
|
||||||
|
@ -5,23 +5,24 @@ import androidx.room.Delete;
|
|||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
|
|
||||||
import java.util.List;
|
import io.reactivex.rxjava3.core.Completable;
|
||||||
import java.util.Optional;
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
|
import io.reactivex.rxjava3.core.Single;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface ConfigDAO {
|
public interface ConfigDAO {
|
||||||
@Query("SELECT * FROM config")
|
@Query("SELECT * FROM config")
|
||||||
List<Config> getAll();
|
Observable<Config> getAll();
|
||||||
|
|
||||||
@Query("SELECT * FROM config WHERE uid IN (:cfgIds)")
|
@Query("SELECT * FROM config WHERE uid IN (:cfgIds)")
|
||||||
List<Config> loadAllByIds(int[] cfgIds);
|
Observable<Config> loadAllByIds(int[] cfgIds);
|
||||||
|
|
||||||
@Query("SELECT * FROM config WHERE uid = :cfgId")
|
@Query("SELECT * FROM config WHERE uid = :cfgId")
|
||||||
Optional<Config> loadById(int cfgId);
|
Single<Config> loadById(int cfgId);
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
void insertAll(Config... users);
|
Completable insertAll(Config... users);
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
void delete(Config user);
|
Completable delete(Config user);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,22 @@
|
|||||||
android:focusable="true" />
|
android:focusable="true" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:background="@color/colorPrimary">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="11111" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/config_list"
|
android:id="@+id/config_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -31,4 +47,6 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
@ -2,4 +2,5 @@
|
|||||||
<string name="app_name">Frida</string>
|
<string name="app_name">Frida</string>
|
||||||
<string name="create_config">Create from scratch</string>
|
<string name="create_config">Create from scratch</string>
|
||||||
<string name="import_config">Import from file</string>
|
<string name="import_config">Import from file</string>
|
||||||
|
<string name="config_adding_error">Cannot add new config</string>
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user