From 07fd2f2f477e7fe3a21512ebc0f55bf23c8d4ceb Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 2 May 2021 22:38:15 -0600 Subject: kindof understand mvvm --- .../example/wiimmterfaceandroid/MainActivity.java | 17 ++++++++++++ .../wiimmterfaceandroid/RecentCodesFragment.java | 7 ++++- .../wiimmterfaceandroid/WatchCodeFragment.java | 17 +++++++++++- .../wiimmterfaceandroid/database/AppDatabase.java | 11 ++++++++ .../database/FriendCodeDao.java | 30 ++++++++++++++++++++++ .../wiimmterfaceandroid/model/FriendCode.java | 13 ++++++++++ .../viewmodel/FriendCodeViewModel.java | 9 +++++++ app/src/main/res/layout/activity_main.xml | 21 +++++++-------- app/src/main/res/layout/activity_wiimmfi.xml | 2 +- .../main/res/layout/friend_code_input_fragment.xml | 1 - 10 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java create mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java create mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java create mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java (limited to 'app/src') 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 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"> - + android:fitsSystemWindows="true" + app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" /> + android:layout_height="wrap_content" + android:hapticFeedbackEnabled="false" + app:layout_constraintTop_toBottomOf="@+id/friend_code_input_fragment" /> - + \ 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 @@ 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" /> -- cgit v1.2.3