mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Preparation for adding ProfileFragmentViewModel
This commit is contained in:
parent
696a8c9c61
commit
faf299f6f0
@ -147,6 +147,11 @@ android {
|
|||||||
exclude 'META-INF/LICENSE.md'
|
exclude 'META-INF/LICENSE.md'
|
||||||
exclude 'META-INF/LICENSE-notice.md'
|
exclude 'META-INF/LICENSE-notice.md'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testOptions.unitTests {
|
||||||
|
includeAndroidResources = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.all {
|
configurations.all {
|
||||||
@ -231,6 +236,9 @@ dependencies {
|
|||||||
githubImplementation 'io.sentry:sentry-android:4.3.0'
|
githubImplementation 'io.sentry:sentry-android:4.3.0'
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
|
||||||
|
testImplementation "androidx.test.ext:junit-ktx:1.1.2"
|
||||||
|
testImplementation "androidx.test:core-ktx:1.3.0"
|
||||||
|
testImplementation "org.robolectric:robolectric:4.5.1"
|
||||||
|
|
||||||
androidTestImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
|
androidTestImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
|
||||||
androidTestImplementation 'androidx.test:core:1.3.0'
|
androidTestImplementation 'androidx.test:core:1.3.0'
|
||||||
|
@ -93,6 +93,7 @@ import awais.instagrabber.utils.TextUtils;
|
|||||||
import awais.instagrabber.utils.Utils;
|
import awais.instagrabber.utils.Utils;
|
||||||
import awais.instagrabber.viewmodels.AppStateViewModel;
|
import awais.instagrabber.viewmodels.AppStateViewModel;
|
||||||
import awais.instagrabber.viewmodels.HighlightsViewModel;
|
import awais.instagrabber.viewmodels.HighlightsViewModel;
|
||||||
|
import awais.instagrabber.viewmodels.ProfileFragmentViewModel;
|
||||||
import awais.instagrabber.webservices.DirectMessagesService;
|
import awais.instagrabber.webservices.DirectMessagesService;
|
||||||
import awais.instagrabber.webservices.FriendshipService;
|
import awais.instagrabber.webservices.FriendshipService;
|
||||||
import awais.instagrabber.webservices.GraphQLService;
|
import awais.instagrabber.webservices.GraphQLService;
|
||||||
@ -139,6 +140,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
private int downloadChildPosition = -1;
|
private int downloadChildPosition = -1;
|
||||||
private long myId;
|
private long myId;
|
||||||
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_PROFILE_POSTS_LAYOUT);
|
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_PROFILE_POSTS_LAYOUT);
|
||||||
|
private LayoutProfileDetailsBinding profileDetailsBinding;
|
||||||
|
private AccountRepository accountRepository;
|
||||||
|
private FavoriteRepository favoriteRepository;
|
||||||
|
private AppStateViewModel appStateViewModel;
|
||||||
|
private boolean disableDm = false;
|
||||||
|
private ProfileFragmentViewModel viewModel;
|
||||||
|
|
||||||
private final ServiceCallback<FriendshipChangeResponse> changeCb = new ServiceCallback<FriendshipChangeResponse>() {
|
private final ServiceCallback<FriendshipChangeResponse> changeCb = new ServiceCallback<FriendshipChangeResponse>() {
|
||||||
@Override
|
@Override
|
||||||
@ -156,7 +163,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
Log.e(TAG, "Error editing relationship", t);
|
Log.e(TAG, "Error editing relationship", t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Runnable usernameSettingRunnable = () -> {
|
private final Runnable usernameSettingRunnable = () -> {
|
||||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||||
if (actionBar != null && !TextUtils.isEmpty(username)) {
|
if (actionBar != null && !TextUtils.isEmpty(username)) {
|
||||||
@ -318,11 +324,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private LayoutProfileDetailsBinding profileDetailsBinding;
|
|
||||||
private AccountRepository accountRepository;
|
|
||||||
private FavoriteRepository favoriteRepository;
|
|
||||||
private AppStateViewModel appStateViewModel;
|
|
||||||
private boolean disableDm = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||||
@ -344,6 +345,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context));
|
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context));
|
||||||
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context));
|
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(context));
|
||||||
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
appStateViewModel = new ViewModelProvider(fragmentActivity).get(AppStateViewModel.class);
|
||||||
|
viewModel = new ViewModelProvider(this).get(ProfileFragmentViewModel.class);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,6 +375,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
shouldRefresh = false;
|
shouldRefresh = false;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
// appStateViewModel.getCurrentUserLiveData().observe(getViewLifecycleOwner(), user -> viewModel.setCurrentUser(user));
|
||||||
binding = FragmentProfileBinding.inflate(inflater, container, false);
|
binding = FragmentProfileBinding.inflate(inflater, container, false);
|
||||||
root = binding.getRoot();
|
root = binding.getRoot();
|
||||||
profileDetailsBinding = binding.header;
|
profileDetailsBinding = binding.header;
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package awais.instagrabber.viewmodels
|
||||||
|
|
||||||
|
import androidx.lifecycle.*
|
||||||
|
import awais.instagrabber.repositories.responses.User
|
||||||
|
|
||||||
|
class ProfileFragmentViewModel(
|
||||||
|
state: SavedStateHandle,
|
||||||
|
) : ViewModel() {
|
||||||
|
private val _profile = MutableLiveData<User?>()
|
||||||
|
val profile: LiveData<User?> = _profile
|
||||||
|
val username: LiveData<String> = Transformations.map(profile) { return@map it?.username ?: "" }
|
||||||
|
|
||||||
|
var currentUser: User? = null
|
||||||
|
var isLoggedIn = false
|
||||||
|
get() = currentUser != null
|
||||||
|
private set
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Log.d(TAG, state.keys().toString())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package awais.instagrabber.viewmodels
|
||||||
|
|
||||||
|
import androidx.lifecycle.SavedStateHandle
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
internal class ProfileFragmentViewModelTest {
|
||||||
|
@Test
|
||||||
|
fun testNoUsernameNoCurrentUser() {
|
||||||
|
val state = SavedStateHandle(mutableMapOf<String, Any>(
|
||||||
|
"username" to ""
|
||||||
|
))
|
||||||
|
val viewModel = ProfileFragmentViewModel(state)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user