diff --git a/app/build.gradle b/app/build.gradle index 78de2910..3ec8b423 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,7 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6dad453e..f524e424 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,9 +33,10 @@ android:name=".activities.AddAccountActivity" android:label="@string/add_account" /> + android:parentActivityName=".activities.MainActivity" + android:theme="@style/AppTheme.NoActionBar" /> { - Intent intent = new Intent(getApplication(), ManageFeedsActivity.class); - intent.putExtra(ManageFeedsActivity.ACCOUNT, account); + Intent intent = new Intent(getApplication(), ManageFeedsFoldersActivity.class); + intent.putExtra(ManageFeedsFoldersActivity.ACCOUNT, account); startActivity(intent); }); diff --git a/app/src/main/java/com/readrops/app/activities/ManageFeedsFoldersActivity.java b/app/src/main/java/com/readrops/app/activities/ManageFeedsFoldersActivity.java new file mode 100644 index 00000000..4b510752 --- /dev/null +++ b/app/src/main/java/com/readrops/app/activities/ManageFeedsFoldersActivity.java @@ -0,0 +1,113 @@ +package com.readrops.app.activities; + +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; + +import com.readrops.app.R; +import com.readrops.app.database.entities.Account; +import com.readrops.app.databinding.ActivityManageFeedsFoldersBinding; +import com.readrops.app.fragments.FeedsFragment; +import com.readrops.app.fragments.FoldersFragment; + +public class ManageFeedsFoldersActivity extends AppCompatActivity { + + public static final String ACCOUNT = "ACCOUNT"; + + private ActivityManageFeedsFoldersBinding binding; + private FeedsFoldersPageAdapter pageAdapter; + + private Account account; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + binding = DataBindingUtil.setContentView(this, R.layout.activity_manage_feeds_folders); + setSupportActionBar(binding.manageFeedsFoldersToolbar); + + account = getIntent().getParcelableExtra(ACCOUNT); + + pageAdapter = new FeedsFoldersPageAdapter(getSupportFragmentManager()); + + binding.manageFeedsFoldersViewpager.setAdapter(pageAdapter); + binding.manageFeedsFoldersTablayout.setupWithViewPager(binding.manageFeedsFoldersViewpager); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.feeds_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.add_folder: + //addFolder(); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onBackPressed() { + finish(); + super.onBackPressed(); + } + + public class FeedsFoldersPageAdapter extends FragmentPagerAdapter { + + private FeedsFoldersPageAdapter(FragmentManager fragmentManager) { + super(fragmentManager); + + } + + @Override + public int getCount() { + return 2; + } + + @Nullable + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case 0: + return getApplicationContext().getString(R.string.feeds_and_folders); + case 1: + return getApplicationContext().getString(R.string.folder); + default: + return null; + } + + + } + + @Override + public Fragment getItem(int position) { + Fragment fragment = null; + + switch (position) { + case 0: + fragment = FeedsFragment.newInstance(account); + break; + case 1: + fragment = FoldersFragment.newInstance(account); + break; + } + + return fragment; + } + } +} diff --git a/app/src/main/java/com/readrops/app/activities/ManageFeedsActivity.java b/app/src/main/java/com/readrops/app/fragments/FeedsFragment.java similarity index 66% rename from app/src/main/java/com/readrops/app/activities/ManageFeedsActivity.java rename to app/src/main/java/com/readrops/app/fragments/FeedsFragment.java index 1ec93d95..2d4433e9 100644 --- a/app/src/main/java/com/readrops/app/activities/ManageFeedsActivity.java +++ b/app/src/main/java/com/readrops/app/fragments/FeedsFragment.java @@ -1,15 +1,19 @@ -package com.readrops.app.activities; +package com.readrops.app.fragments; + import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Vibrator; -import android.view.Menu; -import android.view.MenuItem; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.ItemTouchHelper; @@ -18,9 +22,11 @@ import androidx.recyclerview.widget.RecyclerView; import com.afollestad.materialdialogs.MaterialDialog; import com.readrops.app.R; +import com.readrops.app.activities.AccountSettingsActivity; import com.readrops.app.database.entities.Account; import com.readrops.app.database.entities.Folder; import com.readrops.app.database.pojo.FeedWithFolder; +import com.readrops.app.databinding.FragmentFeedsBinding; import com.readrops.app.viewmodels.ManageFeedsViewModel; import com.readrops.app.views.EditFeedDialog; import com.readrops.app.views.FeedsAdapter; @@ -29,29 +35,58 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.observers.DisposableCompletableObserver; import io.reactivex.schedulers.Schedulers; -public class ManageFeedsActivity extends AppCompatActivity { +import static android.content.Context.VIBRATOR_SERVICE; +import static com.readrops.app.activities.ManageFeedsFoldersActivity.ACCOUNT; - public static final String ACCOUNT = "ACCOUNT"; - private RecyclerView recyclerView; +public class FeedsFragment extends Fragment { + private FeedsAdapter adapter; - private ManageFeedsViewModel viewModel; - private Account account; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_manage_feeds); + private FragmentFeedsBinding binding; - account = getIntent().getParcelableExtra(ACCOUNT); + public FeedsFragment() { + // Required empty public constructor + } + + public static FeedsFragment newInstance(Account account) { + FeedsFragment fragment = new FeedsFragment(); + Bundle args = new Bundle(); + + args.putParcelable(AccountSettingsActivity.ACCOUNT, account); + fragment.setArguments(args); + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + account = getArguments().getParcelable(ACCOUNT); viewModel = ViewModelProviders.of(this).get(ManageFeedsViewModel.class); viewModel.setAccount(account); - recyclerView = findViewById(R.id.feeds_recyclerview); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); + viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> adapter.submitList(feedWithFolders)); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + binding = DataBindingUtil.inflate(inflater, R.layout.fragment_feeds, container, false); + + return binding.getRoot(); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + binding.feedsRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity())); adapter = new FeedsAdapter(new FeedsAdapter.ManageFeedsListener() { @Override @@ -61,7 +96,7 @@ public class ManageFeedsActivity extends AppCompatActivity { @Override public void onOpenLink(FeedWithFolder feedWithFolder) { - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); + Vibrator vibrator = (Vibrator) getActivity().getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(50); Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(feedWithFolder.getFeed().getSiteUrl())); @@ -69,7 +104,7 @@ public class ManageFeedsActivity extends AppCompatActivity { } }); - recyclerView.setAdapter(adapter); + binding.feedsRecyclerview.setAdapter(adapter); new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { @Override @@ -96,13 +131,11 @@ public class ManageFeedsActivity extends AppCompatActivity { return true; } - }).attachToRecyclerView(recyclerView); - - viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> adapter.submitList(feedWithFolders)); + }).attachToRecyclerView(binding.feedsRecyclerview); } private void deleteFolder(int feedId, int position) { - new MaterialDialog.Builder(this) + new MaterialDialog.Builder(getContext()) .title(getString(R.string.delete_feed)) .positiveText(getString(R.string.validate)) .negativeText(getString(R.string.cancel)) @@ -112,12 +145,12 @@ public class ManageFeedsActivity extends AppCompatActivity { .subscribe(new DisposableCompletableObserver() { @Override public void onComplete() { - Toast.makeText(getApplication(), "feed deleted", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "feed deleted", Toast.LENGTH_LONG).show(); } @Override public void onError(Throwable e) { - Toast.makeText(getApplication(), "error on feed deletion", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "error on feed deletion", Toast.LENGTH_LONG).show(); } })) .onNegative(((dialog, which) -> adapter.notifyItemChanged(position))) @@ -129,20 +162,21 @@ public class ManageFeedsActivity extends AppCompatActivity { Bundle bundle = new Bundle(); bundle.putParcelable("feedWithFolder", feedWithFolder); + bundle.putParcelable(ACCOUNT, account); editFeedDialog.setArguments(bundle); - FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.add(editFeedDialog, "").commit(); } private void addFolder() { - new MaterialDialog.Builder(this) + new MaterialDialog.Builder(getActivity()) .title(R.string.add_folder) .positiveText(R.string.validate) .input(R.string.folder, 0, (dialog, input) -> { Folder folder = new Folder(input.toString()); - folder.setAccountId(1); // TODO add account support for creating folders + folder.setAccountId(account.getId()); viewModel.addFolder(folder) .subscribeOn(Schedulers.io()) @@ -150,41 +184,15 @@ public class ManageFeedsActivity extends AppCompatActivity { .subscribe(new DisposableCompletableObserver() { @Override public void onComplete() { - Toast.makeText(getApplication(), "folder inserted", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "folder inserted", Toast.LENGTH_LONG).show(); } @Override public void onError(Throwable e) { - Toast.makeText(getApplication(), "error on folder insertion", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), "error on folder insertion", Toast.LENGTH_LONG).show(); } }); }) .show(); } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.feeds_menu, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.add_folder: - addFolder(); - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public void onBackPressed() { - finish(); - super.onBackPressed(); - } } diff --git a/app/src/main/java/com/readrops/app/fragments/FoldersFragment.java b/app/src/main/java/com/readrops/app/fragments/FoldersFragment.java new file mode 100644 index 00000000..8943bc14 --- /dev/null +++ b/app/src/main/java/com/readrops/app/fragments/FoldersFragment.java @@ -0,0 +1,42 @@ +package com.readrops.app.fragments; + + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; + +import com.readrops.app.R; +import com.readrops.app.database.entities.Account; + +public class FoldersFragment extends Fragment { + + public FoldersFragment() { + // Required empty public constructor + } + + public static FoldersFragment newInstance(Account account) { + FoldersFragment fragment = new FoldersFragment(); + + Bundle args = new Bundle(); + fragment.setArguments(args); + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_folders, container, false); + } + +} diff --git a/app/src/main/java/com/readrops/app/views/EditFeedDialog.java b/app/src/main/java/com/readrops/app/views/EditFeedDialog.java index d57e7042..cd222416 100644 --- a/app/src/main/java/com/readrops/app/views/EditFeedDialog.java +++ b/app/src/main/java/com/readrops/app/views/EditFeedDialog.java @@ -15,6 +15,8 @@ import androidx.lifecycle.ViewModelProviders; import com.google.android.material.textfield.TextInputEditText; import com.readrops.app.R; +import com.readrops.app.activities.ManageFeedsFoldersActivity; +import com.readrops.app.database.entities.Account; import com.readrops.app.database.entities.Feed; import com.readrops.app.database.entities.Folder; import com.readrops.app.database.pojo.FeedWithFolder; @@ -30,16 +32,21 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem private TextInputEditText feedUrl; private Spinner folder; - Map values; + private Map values; private FeedWithFolder feedWithFolder; + private Account account; private ManageFeedsViewModel viewModel; @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { viewModel = ViewModelProviders.of(getActivity()).get(ManageFeedsViewModel.class); + feedWithFolder = getArguments().getParcelable("feedWithFolder"); + account = getArguments().getParcelable(ManageFeedsFoldersActivity.ACCOUNT); + + viewModel.setAccount(account); View v = getActivity().getLayoutInflater().inflate(R.layout.edit_feed_layout, null); @@ -53,8 +60,6 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem viewModel.updateFeedWithFolder(feedWithFolder); }); - - builder.setView(v); fillData(v); diff --git a/app/src/main/res/layout/activity_manage_feeds.xml b/app/src/main/res/layout/activity_manage_feeds.xml deleted file mode 100644 index ab089854..00000000 --- a/app/src/main/res/layout/activity_manage_feeds.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_manage_feeds_folders.xml b/app/src/main/res/layout/activity_manage_feeds_folders.xml new file mode 100644 index 00000000..7d4f7ac4 --- /dev/null +++ b/app/src/main/res/layout/activity_manage_feeds_folders.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_feeds.xml b/app/src/main/res/layout/fragment_feeds.xml new file mode 100644 index 00000000..13ef82c6 --- /dev/null +++ b/app/src/main/res/layout/fragment_feeds.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_folders.xml b/app/src/main/res/layout/fragment_folders.xml new file mode 100644 index 00000000..15f4ad46 --- /dev/null +++ b/app/src/main/res/layout/fragment_folders.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file