From e722c725009788a45b90a9ed593819bf3618612e Mon Sep 17 00:00:00 2001 From: smart2pet Date: Mon, 26 Dec 2022 19:27:23 +0800 Subject: [PATCH] Initial commit --- .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/.name | 1 + .idea/compiler.xml | 6 + .idea/gradle.xml | 19 ++ .idea/misc.xml | 10 + app/.gitignore | 1 + app/build.gradle | 47 +++++ app/proguard-rules.pro | 21 ++ .../mobile/ExampleInstrumentedTest.java | 25 +++ app/src/main/AndroidManifest.xml | 35 ++++ .../main/java/com/smartpet/mobile/Feeder.java | 163 +++++++++++++++ .../com/smartpet/mobile/MainActivity.java | 152 ++++++++++++++ .../ui/dashboard/DashboardFragment.java | 36 ++++ .../ui/dashboard/DashboardViewModel.java | 19 ++ .../smartpet/mobile/ui/home/HomeFragment.java | 36 ++++ .../mobile/ui/home/HomeViewModel.java | 19 ++ .../drawable-v24/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_dashboard_black_24dp.xml | 9 + .../main/res/drawable/ic_home_black_24dp.xml | 9 + .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++ .../drawable/ic_notifications_black_24dp.xml | 9 + app/src/main/res/layout/activity_main.xml | 35 ++++ .../main/res/layout/fragment_dashboard.xml | 63 ++++++ app/src/main/res/layout/fragment_home.xml | 123 ++++++++++++ app/src/main/res/menu/bottom_nav_menu.xml | 14 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes app/src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes .../main/res/navigation/mobile_navigation.xml | 20 ++ app/src/main/res/values-night/themes.xml | 10 + app/src/main/res/values/colors.xml | 10 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 6 + app/src/main/res/values/themes.xml | 10 + app/src/main/res/xml/backup_rules.xml | 13 ++ .../main/res/xml/data_extraction_rules.xml | 19 ++ .../com/smartpet/mobile/ExampleUnitTest.java | 17 ++ build.gradle | 5 + gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 185 ++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle | 16 ++ 54 files changed, 1509 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/smartpet/mobile/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/smartpet/mobile/Feeder.java create mode 100644 app/src/main/java/com/smartpet/mobile/MainActivity.java create mode 100644 app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardFragment.java create mode 100644 app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardViewModel.java create mode 100644 app/src/main/java/com/smartpet/mobile/ui/home/HomeFragment.java create mode 100644 app/src/main/java/com/smartpet/mobile/ui/home/HomeViewModel.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_dashboard_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_home_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_notifications_black_24dp.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/fragment_dashboard.xml create mode 100644 app/src/main/res/layout/fragment_home.xml create mode 100644 app/src/main/res/menu/bottom_nav_menu.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/navigation/mobile_navigation.xml create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/backup_rules.xml create mode 100644 app/src/main/res/xml/data_extraction_rules.xml create mode 100644 app/src/test/java/com/smartpet/mobile/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..1ae38c8 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +SmartPET Feeder Mobile \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..a2d7c21 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bdd9278 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..0491895 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.smartpet.mobile' + compileSdk 32 + + defaultConfig { + applicationId "com.smartpet.mobile" + minSdk 26 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'android.arch.lifecycle:livedata:1.1.1' + implementation 'android.arch.lifecycle:viewmodel:1.1.1' + implementation 'android.arch.navigation:navigation-fragment:1.0.0' + implementation 'android.arch.navigation:navigation-ui:1.0.0' + implementation 'com.android.support:design:28.0.0' + implementation 'com.android.support:gridlayout-v7:28.0.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/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/src/androidTest/java/com/smartpet/mobile/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/smartpet/mobile/ExampleInstrumentedTest.java new file mode 100644 index 0000000..93cc8af --- /dev/null +++ b/app/src/androidTest/java/com/smartpet/mobile/ExampleInstrumentedTest.java @@ -0,0 +1,25 @@ +package com.smartpet.mobile; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.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("com.smartpet.mobile", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b1a3398 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/Feeder.java b/app/src/main/java/com/smartpet/mobile/Feeder.java new file mode 100644 index 0000000..d368632 --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/Feeder.java @@ -0,0 +1,163 @@ +package com.smartpet.mobile; + +import android.text.Spannable; +import android.text.TextUtils; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +class Failed extends Exception { + public Failed(String message) { + super(message); + } +} + +public class Feeder { + String ip; + String uri; + public Feeder(String ip) throws Failed { + try { + HttpURLConnection conn = null; + URL url = new URL("http://" + ip + ":8000"); + this.uri = "http://" + ip + ":8000"; + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.connect(); + if (conn.getResponseCode() == 200) { + this.ip = ip; + } else { + throw (new Failed("Connect failed. ")); + } + } catch (IOException e) { + e.printStackTrace(); +// throw (new IOException()); + throw new Failed("Connect failed. "); + } + } + + public void addFeedingPlan(int hour, int minute, int weight) throws Failed { + try { + StringBuffer sbf = new StringBuffer(); + String strRead = null; + HttpURLConnection conn = null; + URL url = new URL(uri + "/api/plan"); + + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + + conn.connect(); + OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); + writer.write("{\"time_h\":"); + writer.write(String.valueOf(hour)); + writer.write(","); + writer.write("\"time_m\":"); + writer.write(String.valueOf(minute)); + writer.write(","); + writer.write("\"weight\":"); + writer.write(String.valueOf(weight)); + writer.write("}"); + writer.flush(); + InputStream is = conn.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); + while ((strRead = reader.readLine()) != null) { + sbf.append(strRead); + } + reader.close(); + conn.disconnect(); + String results = sbf.toString(); + Log.println(Log.WARN, "FEed", results); + if (!results.equals("{\"result\":0}")) { + throw new Failed("Server returned failed result."); + } else { + Log.println(Log.WARN, "Feeder", "Add feeding plan request sent."); + } + } catch (IOException e) { + e.printStackTrace(); + throw new Failed(""); + } + } + + public void feed(int weight) throws Failed { + try { + StringBuffer sbf = new StringBuffer(); + String strRead = null; + HttpURLConnection conn = null; + URL url = new URL(uri + "/api/food"); + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + + conn.connect(); + OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); + writer.write("{\"weight\": " + String.valueOf(weight) + "}"); + writer.flush(); + InputStream is = conn.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); + while ((strRead = reader.readLine()) != null) { + sbf.append(strRead); + } + reader.close(); + conn.disconnect(); + String results = sbf.toString(); + Log.println(Log.WARN, "FEed", results); + if (!results.equals("{\"result\":0}")) { + throw new Failed("Server returned failed result."); + } else { + Log.println(Log.WARN, "Feeder", "Feeding request sent."); + } + } catch (IOException e) { + e.printStackTrace(); + throw new Failed("Internal error."); + } + } + public void delFeedingPlan(int hour, int minute) throws Failed { + try { + StringBuffer sbf = new StringBuffer(); + String strRead = null; + HttpURLConnection conn = null; + URL url = new URL(uri + "/api/plan"); + + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("DELETE"); + conn.setRequestProperty("Content-Type", "application/json"); + + conn.connect(); + OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); + writer.write("{\"time_h\":"); + writer.write(String.valueOf(hour)); + writer.write(","); + writer.write("\"time_m\":"); + writer.write(String.valueOf(minute)); + writer.write("}"); + writer.flush(); + InputStream is = conn.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); + while ((strRead = reader.readLine()) != null) { + sbf.append(strRead); + } + reader.close(); + conn.disconnect(); + String results = sbf.toString(); + Log.println(Log.WARN, "FEed", results); + if (!results.equals("{\"result\":0}")) { + throw new Failed("Server returned failed result."); + } else { + Log.println(Log.WARN, "Feeder", "Add feeding plan request sent."); + } + } catch (IOException e) { + e.printStackTrace(); + throw new Failed(""); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/MainActivity.java b/app/src/main/java/com/smartpet/mobile/MainActivity.java new file mode 100644 index 0000000..8697d04 --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/MainActivity.java @@ -0,0 +1,152 @@ +package com.smartpet.mobile; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.os.Bundle; +import android.os.StrictMode; +import android.support.design.widget.BottomNavigationView; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.navigation.ui.AppBarConfiguration; +import androidx.navigation.ui.NavigationUI; + +import com.smartpet.mobile.databinding.ActivityMainBinding; +import com.smartpet.mobile.ui.home.HomeFragment; +import com.smartpet.mobile.Feeder; + +import java.io.IOException; + + +public class MainActivity extends AppCompatActivity { + + private ActivityMainBinding binding; + public Feeder feeder; + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + BottomNavigationView navView = findViewById(R.id.nav_view); + // Passing each menu ID as a set of Ids because each + // menu should be considered as top level destinations. + AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( + R.id.navigation_home, R.id.navigation_dashboard) + .build(); + NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main); + NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); + NavigationUI.setupWithNavController(binding.navView, navController); +// try { +// feeder = new Feeder("192.168.1.6:8000"); +// } catch (IOException e) { +// e.printStackTrace(); +// } + } + public void feed(View view) { + int weight; + Object test; + EditText input; + input = (EditText) findViewById(R.id.inputFeedWeight); + String weight_string = input.getText().toString(); + try { + weight = Integer.parseInt(weight_string); + Log.println(Log.WARN, "FEED", String.valueOf(weight)); + feeder.feed(weight); + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Completed"); + normalDialog.setMessage("Successful sent feeding request to feeder. "); + normalDialog.show(); + } catch (NumberFormatException | Failed | NullPointerException e) { + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Error"); + normalDialog.setMessage("Something went wrong... "); + normalDialog.show(); + e.printStackTrace(); + } + } + public void addPlan(View view) { + int hour, minute, weight; + EditText input_time, input_weight; + input_time = (EditText) findViewById(R.id.setTime); + String time_string = input_time.getText().toString(); + try { + hour = Integer.parseInt(time_string.split(":")[0]); + minute = Integer.parseInt(time_string.split(":")[1]); + } catch (Exception ignored){ + return; + } + input_weight = (EditText) findViewById(R.id.planWeight); + String weight_string = input_weight.getText().toString(); +// weight = Integer.parseInt(weight_string); + try { + weight = Integer.parseInt(weight_string); + feeder.addFeedingPlan(hour, minute, weight); + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Completed"); + normalDialog.setMessage("Successful sent add plan request to feeder. "); + normalDialog.show(); + + } catch (Failed | NumberFormatException | NullPointerException e){ + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Error"); + normalDialog.setMessage("Something went wrong... "); + normalDialog.show(); + } + } + @SuppressLint("SetTextI18n") + public void connect(View view) { + String ip; + EditText ip_edit; + TextView status; + ip_edit = (EditText) findViewById(R.id.ip); + status = (TextView) findViewById(R.id.status); + ip = ip_edit.getText().toString(); + try { + this.feeder = new Feeder(ip); + status.setText("Connected!"); + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Completed"); + normalDialog.setMessage("Successful connected. "); + normalDialog.show(); + } catch (Failed ignored) {} + } + public void delPlan(View view) { + int hour, minute; + EditText input_time; + input_time = (EditText) findViewById(R.id.setTime); + String time_string = input_time.getText().toString(); + try { + hour = Integer.parseInt(time_string.split(":")[0]); + minute = Integer.parseInt(time_string.split(":")[1]); + } catch (Exception ignored){ + return; + } +// input_weight = (EditText) findViewById(R.id.planWeight); +// String weight_string = input_weight.getText().toString(); +// weight = Integer.parseInt(weight_string); + try { +// weight = Integer.parseInt(weight_string); + feeder.delFeedingPlan(hour, minute); + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Completed"); + normalDialog.setMessage("Successful sent a delete plan request to feeder. "); + normalDialog.show(); + + } catch (Failed | NumberFormatException | NullPointerException e){ + final AlertDialog.Builder normalDialog = new AlertDialog.Builder(MainActivity.this); + normalDialog.setTitle("Error"); + normalDialog.setMessage("Something went wrong... "); + normalDialog.show(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardFragment.java b/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardFragment.java new file mode 100644 index 0000000..f430173 --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardFragment.java @@ -0,0 +1,36 @@ +package com.smartpet.mobile.ui.dashboard; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.arch.lifecycle.ViewModelProvider; + +import com.smartpet.mobile.databinding.FragmentDashboardBinding; + +public class DashboardFragment extends Fragment { + + private FragmentDashboardBinding binding; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + DashboardViewModel dashboardViewModel = + new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(DashboardViewModel.class); + + binding = FragmentDashboardBinding.inflate(inflater, container, false); + View root = binding.getRoot(); + +// final TextView textView = binding.textDashboard; +// dashboardViewModel.getText().observe(getViewLifecycleOwner(), textView::setText); + return root; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardViewModel.java b/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardViewModel.java new file mode 100644 index 0000000..41ed1dd --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/ui/dashboard/DashboardViewModel.java @@ -0,0 +1,19 @@ +package com.smartpet.mobile.ui.dashboard; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.MutableLiveData; +import android.arch.lifecycle.ViewModel; + +public class DashboardViewModel extends ViewModel { + + private final MutableLiveData mText; + + public DashboardViewModel() { + mText = new MutableLiveData<>(); + mText.setValue("This is dashboard fragment"); + } + + public LiveData getText() { + return mText; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/ui/home/HomeFragment.java b/app/src/main/java/com/smartpet/mobile/ui/home/HomeFragment.java new file mode 100644 index 0000000..dd72e8a --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/ui/home/HomeFragment.java @@ -0,0 +1,36 @@ +package com.smartpet.mobile.ui.home; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.arch.lifecycle.ViewModelProvider; + +import com.smartpet.mobile.databinding.FragmentHomeBinding; + +public class HomeFragment extends Fragment { + + private FragmentHomeBinding binding; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + HomeViewModel homeViewModel = + new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(HomeViewModel.class); + + binding = FragmentHomeBinding.inflate(inflater, container, false); + View root = binding.getRoot(); + +// final TextView textView = binding.textHome; +// homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText); + return root; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/smartpet/mobile/ui/home/HomeViewModel.java b/app/src/main/java/com/smartpet/mobile/ui/home/HomeViewModel.java new file mode 100644 index 0000000..ffc8b55 --- /dev/null +++ b/app/src/main/java/com/smartpet/mobile/ui/home/HomeViewModel.java @@ -0,0 +1,19 @@ +package com.smartpet.mobile.ui.home; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.MutableLiveData; +import android.arch.lifecycle.ViewModel; + +public class HomeViewModel extends ViewModel { + + private final MutableLiveData mText; + + public HomeViewModel() { + mText = new MutableLiveData<>(); + mText.setValue("This is home fragment"); + } + + public LiveData getText() { + return mText; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml new file mode 100644 index 0000000..46fc8de --- /dev/null +++ b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml new file mode 100644 index 0000000..f8bb0b5 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml new file mode 100644 index 0000000..78b75c3 --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..cd6ceaa --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_dashboard.xml b/app/src/main/res/layout/fragment_dashboard.xml new file mode 100644 index 0000000..744d70f --- /dev/null +++ b/app/src/main/res/layout/fragment_dashboard.xml @@ -0,0 +1,63 @@ + + + + + + + + + +