Skip to content

Commit

Permalink
Demo Networker app
Browse files Browse the repository at this point in the history
  • Loading branch information
kaamfor committed May 11, 2024
1 parent 4a13d91 commit 76e0b00
Show file tree
Hide file tree
Showing 82 changed files with 3,334 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
83 changes: 83 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
plugins {
id("com.android.application") version "8.2.2" apply true
id("androidx.navigation.safeargs") version "2.7.7" apply true

// Add the Google services Gradle plugin
id("com.google.gms.google-services")
}

android {
namespace = "com.example.networker"
compileSdk = 34

defaultConfig {
applicationId = "com.example.networker"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

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.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

implementation("io.reactivex.rxjava3:rxjava:3.0.0")
implementation("io.reactivex.rxjava3:rxandroid:3.0.0")

compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")

implementation("me.legrange:mikrotik:3.0.7")

implementation("com.jjoe64:graphview:4.2.2")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation("androidx.preference:preference:1.2.1")
implementation("androidx.fragment:fragment:1.6.2")

// Used by at least bottomNavBar
implementation("com.google.android.material:material:1.11.0")

// Navigation component/graph
implementation("androidx.navigation:navigation-fragment:2.7.7")
implementation("androidx.navigation:navigation-ui:2.7.7")
implementation("androidx.navigation:navigation-dynamic-features-fragment:2.7.7")
androidTestImplementation("androidx.navigation:navigation-testing:2.7.7")
//implementation("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7")

compileOnly("com.android.tools.build:gradle:8.3.2")
// Import the Firebase BoM
implementation(platform("com.google.firebase:firebase-bom:32.8.1"))
// TODO: Add the dependencies for Firebase products you want to use
// When using the BoM, don't specify versions in Firebase dependencies
// https://firebase.google.com/docs/android/setup#available-libraries

////implementation(platform("com.google.firebase:firebase-auth:22.3.1"))
//implementation(platform("com.google.android.gms:play-services-auth:21.1.0"))
implementation("com.google.firebase:firebase-auth")
//implementation("com.google.android.gms:play-services-auth")

implementation("com.google.firebase:firebase-firestore")
//implementation("com.android.support:multidex:1.0.3")
implementation("com.google.firebase:firebase-database")
}
21 changes: 21 additions & 0 deletions app/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 com.example.networker;

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("com.example.networker", appContext.getPackageName());
}
}
34 changes: 34 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Networker"
tools:targetApi="31">
<activity
android:name=".DeviceDetailsActivity"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false" />
</application>

</manifest>
137 changes: 137 additions & 0 deletions app/src/main/java/com/example/networker/DeviceDetailsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.example.networker;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import com.example.networker.database.domain.DummyDeviceBackend;
import com.example.networker.ui.viewmodel.DeviceInterface;
import com.example.networker.ui.viewmodel.DummyDevice;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.HashMap;

public class DeviceDetailsActivity extends AppCompatActivity {
private static final String LOG_TAG = DeviceDetailsActivity.class.getName();

ViewPager2 viewPager;
TabLayout tabChooser;

private int deviceMonitorListGridNumber = 1;
private DummyDeviceBackend dbBackend;

DeviceDetailsActivityTabbing tabAdapter;
private String deviceId;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device_details);

viewPager = findViewById(R.id.viewpager);
tabChooser = findViewById(R.id.tabChooser);

dbBackend = new DummyDeviceBackend();

if (savedInstanceState != null) {
deviceId = savedInstanceState.getString(MainActivity.DEVICEDETAILS_PARAM_DEVICE_ID);
}
else {
deviceId = getIntent().getStringExtra(MainActivity.DEVICEDETAILS_PARAM_DEVICE_ID);
}

//Serializable deviceSerializable = getIntent().getSerializableExtra(MainActivity.DEVICEDETAILS_PARAM_DEVICE);
//if (deviceSerializable != null) {
if (deviceId != null) {
//dummyDevice = DummyDevice.fromMap((HashMap) deviceSerializable);
dbBackend.getUserDevice(MainActivity.getDbCurrentUser().getId(), deviceId).subscribe(
devicePair -> {
DummyDevice dummyDevice = DummyDevice.fromModel(devicePair.second);

Log.i(LOG_TAG, String.valueOf(dummyDevice));
if (dummyDevice != null) {
Log.i(LOG_TAG, "1" + String.valueOf(dummyDevice.getSettings()));
if (dummyDevice.getSettings() != null) {
Log.i(LOG_TAG, "2" + String.valueOf(dummyDevice.getSettings().getInterfaceList()));
if (dummyDevice.getSettings().getInterfaceList() != null) {
for (com.example.networker.database.model.device.DeviceInterface deviceInterface : dummyDevice.getSettings().getInterfaceList()) {
Log.i(LOG_TAG, "3" + String.valueOf(deviceInterface));
if (deviceInterface != null) {
Log.i(LOG_TAG, "4" + String.valueOf(deviceInterface.getAddress()));
}
}
}
}
}

tabAdapter = new DeviceDetailsActivityTabbing(this, dummyDevice);
setupFragments();
}
);
}
else {
tabAdapter = new DeviceDetailsActivityTabbing(this);
setupFragments();
}
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(MainActivity.DEVICEDETAILS_PARAM_DEVICE_ID, deviceId);
}

private void setupFragments() {
viewPager.setAdapter(tabAdapter);
new TabLayoutMediator(tabChooser, viewPager,
(tab, position) -> tab.setText(tabAdapter.getTabNames().get(position))
).attach();

// DummyDeviceDetailsFragment
getSupportFragmentManager().setFragmentResultListener(
DummyDeviceDetailsFragment.RESULT_DEVICE,
this,
(requestKey, bundle) -> {
HashMap<String,String> deviceMap = (HashMap<String, String>) bundle.getSerializable(DummyDeviceDetailsFragment.RESULT_DEVICE);

saveDevice(DummyDevice.fromMap(deviceMap));
finish();
}
);

// DummyDeviceSettingsFragment
getSupportFragmentManager().setFragmentResultListener(
DummyDeviceSettingsFragment.RESULT_INTERFACE,
this,
(requestKey, bundle) -> {
HashMap<String,String> interfaceMap = (HashMap<String, String>) bundle.getSerializable(DummyDeviceSettingsFragment.RESULT_INTERFACE);

addNewInterface(DeviceInterface.fromMap(interfaceMap));
}
);
getSupportFragmentManager().setFragmentResultListener(
DummyDeviceSettingsFragment.DELETE_INTERFACE,
this,
(requestKey, bundle) -> {
int interfacePos = bundle.getInt(DummyDeviceSettingsFragment.DELETE_INTERFACE);
deleteInterface(interfacePos);
}
);
}

protected void saveDevice(DummyDevice device) {
dbBackend.setUserDevice(MainActivity.getDbCurrentUser().getId(), deviceId, device.toModel());
}

protected void addNewInterface(com.example.networker.database.model.device.DeviceInterface deviceInterface) {
dbBackend.addInterface(MainActivity.getDbCurrentUser().getId(), deviceId, deviceInterface);
}

protected void deleteInterface(int position) {
dbBackend.deleteInterface(MainActivity.getDbCurrentUser().getId(), deviceId, position);
}
}
Loading

0 comments on commit 76e0b00

Please sign in to comment.