diff options
author | Bryson Steck <steck.bryson@gmail.com> | 2021-05-02 22:38:15 -0600 |
---|---|---|
committer | Bryson Steck <steck.bryson@gmail.com> | 2021-05-02 22:38:15 -0600 |
commit | 07fd2f2f477e7fe3a21512ebc0f55bf23c8d4ceb (patch) | |
tree | 99b43838373fc35a332e3c8977bba2e3b881dd28 | |
parent | 1bf7224e155380ec3921cc62f36eb4f5a47d3b80 (diff) | |
download | wiimmfi-watcher-07fd2f2f477e7fe3a21512ebc0f55bf23c8d4ceb.tar wiimmfi-watcher-07fd2f2f477e7fe3a21512ebc0f55bf23c8d4ceb.tar.gz wiimmfi-watcher-07fd2f2f477e7fe3a21512ebc0f55bf23c8d4ceb.tar.bz2 |
kindof understand mvvm
11 files changed, 133 insertions, 14 deletions
diff --git a/app/build.gradle b/app/build.gradle index a525737..ecfb534 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,4 +38,23 @@ dependencies { testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + dependencies { + def room_version = "2.3.0" + + implementation "androidx.room:room-runtime:$room_version" + annotationProcessor "androidx.room:room-compiler:$room_version" + + // optional - RxJava2 support for Room + implementation "androidx.room:room-rxjava2:$room_version" + + // optional - RxJava3 support for Room + implementation "androidx.room:room-rxjava3:$room_version" + + // optional - Guava support for Room, including Optional and ListenableFuture + implementation "androidx.room:room-guava:$room_version" + + // optional - Test helpers + testImplementation "androidx.room:room-testing:$room_version" + } + }
\ No newline at end of file diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java b/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java index abf1391..b8f7905 100644 --- a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java +++ b/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java @@ -3,14 +3,31 @@ package com.example.wiimmterfaceandroid; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentContainerView; +import androidx.room.Room; import android.os.Bundle; +import com.example.wiimmterfaceandroid.database.AppDatabase; + public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + FragmentContainerView fcInput = findViewById(R.id.recent_friend_codes_fragment); + AppDatabase database = Room.databaseBuilder(this, AppDatabase.class, "friend-codes-db").build(); + setContentView(R.layout.activity_main); + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.friend_code_input_fragment, WatchCodeFragment.class, null) + .setReorderingAllowed(true) + .commit(); + getSupportFragmentManager().beginTransaction() + .replace(R.id.recent_friend_codes_fragment, RecentCodesFragment.class, null) + .setReorderingAllowed(true) + .commit(); + } } }
\ No newline at end of file diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java index 886743f..7dff276 100644 --- a/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java +++ b/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java @@ -1,4 +1,9 @@ package com.example.wiimmterfaceandroid; -public class RecentCodesFragment { +import androidx.fragment.app.Fragment; + +public class RecentCodesFragment extends Fragment { + + public RecentCodesFragment() { super(R.layout.fragment_recent_friend_codes); } + } diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java index bb2385a..145fb2c 100644 --- a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java +++ b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java @@ -1,4 +1,19 @@ package com.example.wiimmterfaceandroid; -public class WatchCodeFragment { +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +public class WatchCodeFragment extends Fragment { + + public WatchCodeFragment() { super(R.layout.friend_code_input_fragment); } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + } } diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java b/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java new file mode 100644 index 0000000..0f01149 --- /dev/null +++ b/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java @@ -0,0 +1,11 @@ +package com.example.wiimmterfaceandroid.database; + +import androidx.room.Database; +import androidx.room.RoomDatabase; + +import com.example.wiimmterfaceandroid.model.FriendCode; + +@Database(entities = {FriendCode.class}, version=1) +public abstract class AppDatabase extends RoomDatabase { + public abstract FriendCodeDao getFriendCodeDao(); +} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java b/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java new file mode 100644 index 0000000..e9762fd --- /dev/null +++ b/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java @@ -0,0 +1,30 @@ +package com.example.wiimmterfaceandroid.database; + +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; + +import com.example.wiimmterfaceandroid.model.FriendCode; + +import java.util.List; + +@Dao +public interface FriendCodeDao { + + @Query("SELECT * FROM friendcode") + public List<FriendCode> getAll(); + + @Query("SELECT * FROM friendcode") + public FriendCode findByCode(String friendCode); + + @Insert + public void insert(FriendCode friendCode); + + @Update + public void update(FriendCode friendCode); + + @Delete + public void delete(FriendCode friendCode); +} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java b/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java new file mode 100644 index 0000000..4d1cc5e --- /dev/null +++ b/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java @@ -0,0 +1,13 @@ +package com.example.wiimmterfaceandroid.model; + +import androidx.room.ColumnInfo; +import androidx.room.Entity; + +@Entity +public class FriendCode { + @ColumnInfo(name="name") + public String name; + + @ColumnInfo(name="friendCode") + public String friendCode; +} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java new file mode 100644 index 0000000..82b892a --- /dev/null +++ b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java @@ -0,0 +1,9 @@ +package com.example.wiimmterfaceandroid.viewmodel; + +import com.example.wiimmterfaceandroid.model.FriendCode; + +public class FriendCodeViewModel { + FriendCode friendCode = new FriendCode(); + + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 47d93ae..e13dc7b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,16 +7,17 @@ android:id="@+id/drawer_layout" tools:context=".MainActivity"> - <androidx.coordinatorlayout.widget.CoordinatorLayout + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <com.google.android.material.appbar.AppBarLayout - style="@style/Widget.MaterialComponents.AppBarLayout.Primary" + android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true"> + android:fitsSystemWindows="true" + app:layout_constraintTop_toTopOf="parent"> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" @@ -31,22 +32,22 @@ </com.google.android.material.appbar.AppBarLayout> <androidx.fragment.app.FragmentContainerView - android:id="@+id/fragment_container2" + android:id="@+id/friend_code_input_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" - app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" /> <androidx.fragment.app.FragmentContainerView - android:id="@+id/fragment_container" + android:id="@+id/recent_friend_codes_fragment" android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior" - /> + android:layout_height="wrap_content" + android:hapticFeedbackEnabled="false" + app:layout_constraintTop_toBottomOf="@+id/friend_code_input_fragment" /> <!-- Screen content --> <!-- Use app:layout_behavior="@string/appbar_scrolling_view_behavior" to fit below top app bar --> - </androidx.coordinatorlayout.widget.CoordinatorLayout> + </androidx.constraintlayout.widget.ConstraintLayout> </androidx.drawerlayout.widget.DrawerLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/activity_wiimmfi.xml b/app/src/main/res/layout/activity_wiimmfi.xml index c7a94fd..1d4d077 100644 --- a/app/src/main/res/layout/activity_wiimmfi.xml +++ b/app/src/main/res/layout/activity_wiimmfi.xml @@ -31,7 +31,7 @@ </com.google.android.material.appbar.AppBarLayout> <androidx.fragment.app.FragmentContainerView - android:id="@+id/fragment_container" + android:id="@+id/recent_friend_codes_fragment" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> diff --git a/app/src/main/res/layout/friend_code_input_fragment.xml b/app/src/main/res/layout/friend_code_input_fragment.xml index 66c62ed..b834f75 100644 --- a/app/src/main/res/layout/friend_code_input_fragment.xml +++ b/app/src/main/res/layout/friend_code_input_fragment.xml @@ -22,7 +22,6 @@ android:drawablePadding="15dp" android:ems="10" android:inputType="textPersonName" - android:text="Friend code" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView2" /> |