Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 1.3.3(2017-11-02)
## 1.3.5(2018-03-07)

- Updated dependencies (Support library, build tools, Gradle).

## 1.3.4(2017-11-02)

- Update Gradle plugin. Fix Nullable annotation in getBinding().

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
AndroidViewModel
================

<b>Important notice: Deprecated</b>
--------
<b>This library served it's purpose for over 3 years. We believe that Google's Android [Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html) are the preferred setup now for new projects. </b>
<b>[INLOOPX](http://www.inloopx.com) is dedicated to continue maintaining this library (no deadline on support end). So rest assured that your existing projects don't need be migrated from AndroidViewModel because of this deprecation. We are only stopping new feature development and don't recommend using it for new projects.</b>


Separating data and state handling from Fragments or Activities without lots of boilerplate-code. Reducing them to simple <i>dumb views</i>.

<b>Basic idea behind this library</b>.
Expand Down Expand Up @@ -87,7 +93,7 @@ Data binding is supported - extend [ViewModelBaseBindingFragment.java](library/s
``` java
@Override
public ViewModelBindingConfig getViewModelBindingConfig() {
return new ViewModelBindingConfig(R.layout.fragment_sample_binding, getActivity());
return new ViewModelBindingConfig(R.layout.fragment_sample_binding, requireActivity());
}
```

Expand All @@ -112,7 +118,7 @@ Download
--------

```groovy
compile 'eu.inloop:androidviewmodel:1.3.4'
compile 'eu.inloop:androidviewmodel:1.3.5'
```

## Android Studio Template
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=1.3.4
VERSION_NAME=1.3.5
15 changes: 8 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName VERSION_NAME
consumerProguardFiles 'proguard-rules.pro'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
}
Expand All @@ -26,8 +26,9 @@ android {
}

dependencies {
implementation 'com.android.support:support-fragment:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-fragment:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'

androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.inloop.viewmodel.fixture.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -15,19 +16,19 @@ public class VMTestFragment extends ViewModelBaseFragment<IVMTestFragmentView, V

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return new LinearLayout(getContext());
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setModelView(this);
}

@Override
public void onLoadData(boolean loaded) {
getActivity().setResult(VMTestActivity.RESULT_CODE_OK);
getActivity().finish();
requireActivity().setResult(VMTestActivity.RESULT_CODE_OK);
requireActivity().finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public static Class<?> getGenericType(@NonNull Class<?> in, @NonNull Class<?> wh
return null;
}

private static final InvocationHandler sInvocationHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
};
private static final InvocationHandler sInvocationHandler = (proxy, method, args) -> null;

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ public void onDestroy(@NonNull final Fragment fragment) {
//no viewmodel for this fragment
return;
}
if (fragment.getActivity().isFinishing()) {
removeViewModel(fragment.getActivity());
if (fragment.requireActivity().isFinishing()) {
removeViewModel(fragment.requireActivity());
} else if (fragment.isRemoving() && !mOnSaveInstanceCalled) {
// The fragment can be still in backstack even if isRemoving() is true.
// We check mOnSaveInstanceCalled - if this was not called then the fragment is totally removed.
if (BuildConfig.DEBUG) {
Log.d("mode", "Removing viewmodel - fragment replaced"); //NON-NLS
}
removeViewModel(fragment.getActivity());
removeViewModel(fragment.requireActivity());
}
mBinding = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
//noinspection unchecked
viewModelClass = (Class<? extends AbstractViewModel<T>>) ProxyViewHelper.getGenericType(getClass(), AbstractViewModel.class);
}
getViewModelHelper().onCreate(getActivity(), savedInstanceState, viewModelClass, getArguments());
getViewModelHelper().onCreate(requireActivity(), savedInstanceState, viewModelClass, getArguments());
}

@CallSuper
Expand Down Expand Up @@ -94,7 +94,7 @@ public ViewModelHelper<T, R> getViewModelHelper() {

@Override
public void removeViewModel() {
mViewModelHelper.removeViewModel(getActivity());
mViewModelHelper.removeViewModel(requireActivity());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getViewModelHelper().performBinding(this);
final ViewDataBinding binding = getViewModelHelper().getBinding();
if (binding != null) {
Expand Down
15 changes: 8 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId 'eu.inloop.viewmodel.sample'
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName '1.0'
}

compileOptions {
encoding "UTF-8"
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
Expand All @@ -30,8 +30,9 @@ android {
}

dependencies {
implementation 'com.android.support:support-fragment:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-fragment:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
implementation 'com.jakewharton:butterknife:8.8.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import butterknife.ButterKnife;
import eu.inloop.viewmodel.base.ViewModelBaseEmptyActivity;
import eu.inloop.viewmodel.sample.R;
import eu.inloop.viewmodel.sample.fragment.PagerFragment;
import eu.inloop.viewmodel.support.ViewModelStatePagerAdapter;

public class ViewPagerActivity extends ViewModelBaseEmptyActivity {

@BindView(R.id.pager)
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pager);

final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new TestPagerAdapter(getSupportFragmentManager()));
ButterKnife.bind(this);
mViewPager.setAdapter(new TestPagerAdapter(getSupportFragmentManager()));
}

private final static class TestPagerAdapter extends ViewModelStatePagerAdapter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.inloop.viewmodel.sample.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -28,12 +29,12 @@ public static PagerFragment newInstance(int position) {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_pager, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
((TextView)view.findViewById(R.id.text)).setText(Integer.toString(getArguments().getInt("position")));
setModelView(this);
Expand All @@ -44,7 +45,7 @@ public void onDestroy() {
super.onDestroy();

// watch for memory leaks
RefWatcher refWatcher = SampleApplication.getRefWatcher(getActivity());
RefWatcher refWatcher = SampleApplication.getRefWatcher(requireActivity());
refWatcher.watch(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.inloop.viewmodel.sample.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
Expand All @@ -24,13 +25,13 @@ public SampleBindingFragment() {
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setModelView(this);
}

@Override
public ViewModelBindingConfig getViewModelBindingConfig() {
return new ViewModelBindingConfig(R.layout.fragment_sample_binding, getActivity());
return new ViewModelBindingConfig(R.layout.fragment_sample_binding, requireActivity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -44,46 +45,46 @@ public class UserListFragment extends ViewModelBaseFragment<IUserListView, UserL
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, new ArrayList<String>());
mAdapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, new ArrayList<String>());
}

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_userlist, container, false);
ButterKnife.bind(this, view);

final View headerView = inflater.inflate(R.layout.view_header_info, null, false);
headerView.findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getFragmentManager().beginTransaction().replace(R.id.root_content, SampleBundleFragment.newInstance(1234), "empty-fragment").addToBackStack(null).commit();
requireFragmentManager().beginTransaction().replace(R.id.root_content, SampleBundleFragment.newInstance(1234), "empty-fragment").addToBackStack(null).commit();
}
});
headerView.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().finish();
getActivity().startActivity(getActivity().getIntent());
requireActivity().finish();
requireActivity().startActivity(requireActivity().getIntent());
}
});
headerView.findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getContext(), ViewPagerActivity.class));
startActivity(new Intent(requireContext(), ViewPagerActivity.class));
}
});
mListview.addHeaderView(headerView, null, false);
mOpenBindingFragment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(SampleBindingActivity.newIntent(getActivity()));
startActivity(SampleBindingActivity.newIntent(requireActivity()));
}
});
return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mListview.setAdapter(mAdapter);
mListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
Expand Down Expand Up @@ -120,7 +121,7 @@ public void onDestroy() {
super.onDestroy();

// watch for memory leaks
RefWatcher refWatcher = SampleApplication.getRefWatcher(getActivity());
RefWatcher refWatcher = SampleApplication.getRefWatcher(requireActivity());
refWatcher.watch(this);
}
}
Loading