パッケージ名のミスを修正, DI実装

This commit is contained in:
ろむねこ 2023-12-10 18:27:14 +09:00
parent 15ee6f344f
commit 24332576e2
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
10 changed files with 24 additions and 18 deletions

View File

@ -57,6 +57,7 @@ dependencies {
// implementation project(':data:source:database')
// implementation project(':data:source:preference')
//
implementation project(':data')
// Hilt (DI)
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler

View File

@ -12,6 +12,8 @@ import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import dagger.hilt.android.AndroidEntryPoint;
import javax.inject.Inject;

View File

@ -4,7 +4,7 @@ plugins {
}
android {
namespace 'com.example.lacerta.data'
namespace 'one.nem.lacerta.data'
compileSdk 34
defaultConfig {

View File

@ -1,4 +1,4 @@
package com.example.lacerta.data;
package one.nem.lacerta.data;
import android.content.Context;
@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.lacerta.data.test", appContext.getPackageName());
assertEquals("one.nem.lacerta.data.test", appContext.getPackageName());
}
}

View File

@ -1,6 +1,6 @@
package com.example.lacerta.data.impl;
package one.nem.lacerta.data.impl;
import com.example.lacerta.data.repository.DeviceMeta;
import one.nem.lacerta.data.repository.DeviceMeta;
import javax.inject.Inject;

View File

@ -1,9 +1,7 @@
package com.example.lacerta.data.module;
package one.nem.lacerta.data.module;
import android.app.Application;
import com.example.lacerta.data.impl.DeviceMetaImpl;
import com.example.lacerta.data.repository.DeviceMeta;
import one.nem.lacerta.data.impl.DeviceMetaImpl;
import one.nem.lacerta.data.repository.DeviceMeta;
import dagger.Binds;
import dagger.Module;

View File

@ -1,4 +1,4 @@
package com.example.lacerta.data.repository;
package one.nem.lacerta.data.repository;
public interface DeviceMeta {
String getDeviceId();

View File

@ -1,4 +1,4 @@
package com.example.lacerta.data;
package one.nem.lacerta.data;
import org.junit.Test;

View File

@ -45,7 +45,6 @@ dependencies {
//
// data
implementation project(':data')

View File

@ -13,6 +13,9 @@ import android.widget.Toast;
import dagger.hilt.android.AndroidEntryPoint;
import javax.inject.Inject;
import one.nem.lacerta.data.repository.DeviceMeta;
/**
* A simple {@link Fragment} subclass.
* Use the {@link DebugMenuFragment#newInstance} factory method to
@ -22,6 +25,9 @@ import javax.inject.Inject;
@AndroidEntryPoint
public class DebugMenuFragment extends Fragment {
@Inject
DeviceMeta deviceMeta;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@ -74,11 +80,11 @@ public class DebugMenuFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Button button = view.findViewById(R.id.button_di_test);
// // Lambda
// button.setOnClickListener(v -> {
// Toast.makeText(getContext(), testData.getTestData(), Toast.LENGTH_SHORT).show();
// });
Button button = view.findViewById(R.id.button_di_test);
// Lambda
button.setOnClickListener(v -> {
Toast.makeText(getContext(), deviceMeta.getDeviceId(), Toast.LENGTH_SHORT).show();
});
}
}