Skip to content

Commit

Permalink
update - NO MORE ROTATION!!!
Browse files Browse the repository at this point in the history
+ REMOVED OTHER ORIENTATIONS!!
+ removed collapsing toolbar layout
+ removed refresh button
+ added swipe refresh layout
  • Loading branch information
AwaisKing committed Jul 17, 2018
1 parent f7a8255 commit 4ffd115
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 167 deletions.
4 changes: 2 additions & 2 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "awais.backworddictionary"
minSdkVersion 16
targetSdkVersion 28
versionCode 60
versionName "6.0"
versionCode 65
versionName "6.5"
multiDexEnabled true
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:fullBackupContent="@xml/backup_descriptor">

<activity android:name=".Main" android:theme="@style/AppTheme" android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden">
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected FilterResults performFiltering(CharSequence charSequence) {
Toast.makeText(mContext, "Select a filter first.", Toast.LENGTH_SHORT).show();
return results;
}

List<WordItem> filteredList = new ArrayList<>();
for (WordItem mWord : wordList) {
String word = mWord.getWord().toLowerCase();
Expand Down Expand Up @@ -210,7 +211,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
} catch (Exception e) {
customTabsIntent.setToolbarColor(Color.parseColor("#4888f2"));
CustomTabActivityHelper.openCustomTab(
(Activity) mContext, customTabsIntent.build(), Uri.parse("https://google.com/search?q=" + wordRawGoogle));
(Activity) mContext, customTabsIntent.build(), Uri.parse("https://google.com/search?q=".concat(wordRawGoogle)));
}

return true;
Expand All @@ -221,19 +222,19 @@ public boolean onMenuItemClick(MenuItem menuItem) {
Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_VIEW);
intent1.setPackage("org.wikipedia");
intent1.setData(Uri.parse("https://en.wikipedia.org/wiki/" + wordRawWiki));
intent1.setData(Uri.parse("https://en.wikipedia.org/wiki/".concat(wordRawWiki)));
List<ResolveInfo> resInfo1 = mContext.getPackageManager().queryIntentActivities(intent1, 0);
if (resInfo1 != null && resInfo1.size() > 0) mContext.startActivity(intent1);
else {
customTabsIntent.setToolbarColor(Color.parseColor("#333333"));
CustomTabActivityHelper.openCustomTab(
(Activity) mContext, customTabsIntent.build(), Uri.parse("https://en.wikipedia.org/wiki/" + wordRawWiki));
(Activity) mContext, customTabsIntent.build(), Uri.parse("https://en.wikipedia.org/wiki/".concat(wordRawWiki)));
}
return true;
case R.id.action_urban:
customTabsIntent.setToolbarColor(Color.parseColor("#3b496b"));
CustomTabActivityHelper.openCustomTab(
(Activity) mContext, customTabsIntent.build(), Uri.parse("http://www.urbandictionary.com/define.php?term=" + currentWord.getWord()));
(Activity) mContext, customTabsIntent.build(), Uri.parse("http://www.urbandictionary.com/define.php?term=".concat(currentWord.getWord())));

return true;
default:
Expand Down
41 changes: 25 additions & 16 deletions app/src/main/java/awais/backworddictionary/DictionaryFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
Expand All @@ -23,7 +24,6 @@
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
Expand All @@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicReference;

import awais.backworddictionary.asyncs.WordsAsync;
import awais.backworddictionary.custom.WordItem;
Expand All @@ -41,7 +42,6 @@
public class DictionaryFragment extends Fragment implements FragmentCallback, FilterCheck {
private List<WordItem> wordList;
private RecyclerView recyclerView;
private ProgressBar progressWords;
private TextToSpeech tts;
private Activity activity;

Expand All @@ -55,6 +55,14 @@ public class DictionaryFragment extends Fragment implements FragmentCallback, Fi
public String title;

private FilterCheck filterChecker;
private static FragmentCallback mainCallback;
private static final AtomicReference<SwipeRefreshLayout> refreshLayout = new AtomicReference<>();

public DictionaryFragment createNew(FragmentCallback callback, SwipeRefreshLayout refreshLayout) {
DictionaryFragment.mainCallback = callback;
DictionaryFragment.refreshLayout.set(refreshLayout);
return new DictionaryFragment();
}

@Override
public void onCreate(Bundle bundle) {
Expand Down Expand Up @@ -92,18 +100,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onAdLoaded() { adView.setVisibility(View.VISIBLE); }
});

progressWords = magicRootView.findViewById(R.id.progressWords);

wordList = new ArrayList<>();
adapter = new DictionaryAdapter(getContext(), wordList, tts);
adapter.setHasStableIds(true);

recyclerView = magicRootView.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
// FastScroller fastScroller = magicRootView.findViewById(R.id.fastscroller);
// fastScroller.setHandleColor(getResources().getColor(R.color.colorAccent));
recyclerView.setAdapter(adapter);
// fastScroller.setRecyclerView(recyclerView);

filterChecker = this;

Expand All @@ -115,14 +118,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
filterSearchButton.setTag("filter");
filterSearchEditor.setOnClickListener(view -> openKeyboard());
filterSearchEditor.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (wordList.size() > 2) adapter.getFilter().filter(charSequence);
@Override public void beforeTextChanged(CharSequence cs, int i, int i1, int i2) {}
@Override public void onTextChanged(CharSequence cs, int i, int i1, int i2) {
if (wordList.size() > 2) adapter.getFilter().filter(cs);
}
@Override
public void afterTextChanged(Editable editable) {
@Override public void afterTextChanged(Editable editable) {
if (editable.length() > 0) {
filterSearchButton.setImageResource(R.drawable.ic_clear);
filterSearchButton.setTag("clear");
Expand Down Expand Up @@ -178,13 +178,20 @@ private void openKeyboard() {
public void startWords(int method, String word) {
if (filterView != null && filterSearchEditor != null) filterSearchEditor.setText("");
if (word == null || word.isEmpty() || TextUtils.isEmpty(word)) return;
new WordsAsync(activity, this, word, method, progressWords, recyclerView).execute();
new WordsAsync(getActivity(),this, word, method, refreshLayout.get(), recyclerView).execute();
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
activity = (Activity) context;
if (getActivity() != null) activity = getActivity();
else activity = (Activity) context;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
activity = getActivity();
}

@Override
Expand All @@ -196,6 +203,8 @@ public void done(ArrayList<WordItem> items, final String word) {

title = word;
activity.setTitle(title);

if (mainCallback != null) mainCallback.done(items, word);
}

public boolean isFilterOpen() {
Expand Down
78 changes: 49 additions & 29 deletions app/src/main/java/awais/backworddictionary/Main.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package awais.backworddictionary;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.TooltipCompat;
import android.text.TextUtils;
Expand All @@ -28,7 +28,6 @@

import com.google.android.gms.ads.MobileAds;
import com.keiferstone.nonet.ConnectionStatus;
import com.keiferstone.nonet.Monitor;
import com.keiferstone.nonet.NoNet;
import com.lapism.searchview.SearchAdapter;
import com.lapism.searchview.SearchView;
Expand All @@ -37,34 +36,42 @@
import java.util.List;

import awais.backworddictionary.asyncs.SearchAsync;
import awais.backworddictionary.custom.AdvancedDialog;
import awais.backworddictionary.custom.MenuCaller;
import awais.backworddictionary.custom.SettingsDialog;
import awais.backworddictionary.interfaces.FragmentCallback;

public class Main extends AppCompatActivity {
public class Main extends AppCompatActivity implements AppBarLayout.OnOffsetChangedListener {
public ViewPager viewPager;
public DictionariesAdapter adapter;
private SearchView mSearchView;
public static SearchAdapter searchAdapter;
private FloatingActionButton fabFilter;
private MenuCaller menuCaller;
private ImageView noInternet;
private AppBarLayout appBarLayout;
private SwipeRefreshLayout swipeRefreshLayout;

public static SharedPreferences sharedPreferences;

@SuppressLint("ClickableViewAccessibility") @Override
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

viewPager = findViewById(R.id.viewpager);
noInternet = findViewById(R.id.noInternet);
fabFilter = findViewById(R.id.filterButton);
appBarLayout = findViewById(R.id.appbarLayout);
swipeRefreshLayout = findViewById(R.id.swipe_container);
swipeRefreshLayout.setColorSchemeResources(R.color.progress1, R.color.progress2,
R.color.progress3, R.color.progress4);

menuCaller = new MenuCaller(this);
sharedPreferences = getSharedPreferences("settings", MODE_PRIVATE);
setSupportActionBar(findViewById(R.id.toolbar));

setupNoNet(false);
setupNoNet();

MobileAds.initialize(this, "ca-app-pub-6411761147229517~1317441366");

Expand All @@ -75,9 +82,16 @@ protected void onCreate(Bundle savedInstanceState) {
fabFilter.setOnClickListener(view ->
adapter.getItem(viewPager.getCurrentItem()).isOpen(true, fabFilter, 0));

findViewById(R.id.shadow).setOnTouchListener((view, motionEvent) -> false);

handleData();

swipeRefreshLayout.setOnRefreshListener(() -> {
swipeRefreshLayout.setRefreshing(true);
if (mSearchView != null) mSearchView.close(true);
if (!getTitle().equals(getResources().getString(R.string.app_name)))
onSearch(getTitle());
else
swipeRefreshLayout.setRefreshing(false);
});
}

private void handleData() {
Expand Down Expand Up @@ -110,10 +124,8 @@ protected void onNewIntent(Intent intent) {
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);

menu.findItem(R.id.mRefresh).setOnMenuItemClickListener(item -> {
if (mSearchView != null) mSearchView.close(true);
if (!getTitle().equals(getResources().getString(R.string.app_name)))
onSearch(getTitle());
menu.findItem(R.id.mAdvance).setOnMenuItemClickListener(item -> {
new AdvancedDialog(this).show();
return true;
});

Expand Down Expand Up @@ -146,6 +158,12 @@ public void onSearch(String word) {
}
}

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
if (!swipeRefreshLayout.isRefreshing())
swipeRefreshLayout.setEnabled(i == 0);
}

public class DictionariesAdapter extends FragmentPagerAdapter {
private final List<DictionaryFragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
Expand Down Expand Up @@ -178,9 +196,10 @@ public boolean onOptionsItemSelected(MenuItem item) {

private void setupLayout() {
adapter = new DictionariesAdapter(getSupportFragmentManager());
adapter.addFrag(new DictionaryFragment(), "Reverse");
adapter.addFrag(new DictionaryFragment(), "Sounds Like");
adapter.addFrag(new DictionaryFragment(), "Spelled Like");
FragmentCallback fragmentCallback = (items, word) -> swipeRefreshLayout.setRefreshing(false);
adapter.addFrag(new DictionaryFragment().createNew(fragmentCallback, swipeRefreshLayout), "Reverse");
adapter.addFrag(new DictionaryFragment().createNew(fragmentCallback, swipeRefreshLayout), "Sounds Like");
adapter.addFrag(new DictionaryFragment().createNew(fragmentCallback, swipeRefreshLayout), "Spelled Like");
viewPager.setOffscreenPageLimit(5);

TabLayout tabLayout = findViewById(R.id.tabs);
Expand Down Expand Up @@ -308,16 +327,9 @@ public boolean onOpen() {
}
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setupNoNet(true);
}

private void setupNoNet(boolean isConfig) {
Monitor.Builder noNet = NoNet.monitor(this).configure(NoNet.configure().endpoint("http://api.datamuse.com/words").build());
if (!isConfig) noNet = noNet.poll();
noNet = noNet.callback(connectionStatus -> {
private void setupNoNet() {
NoNet.monitor(this).configure(NoNet.configure().endpoint("http://api.datamuse.com/words")
.build()).poll().callback(connectionStatus -> {
if (connectionStatus != ConnectionStatus.CONNECTED) {
if (adapter != null && adapter.getItem(viewPager.getCurrentItem()).adapter != null
&& adapter.getItem(viewPager.getCurrentItem()).adapter.getItemCount() < 1) {
Expand Down Expand Up @@ -350,11 +362,19 @@ private void setupNoNet(boolean isConfig) {
((View) fabFilter.getParent()).setBackgroundColor(getResources().getColor(R.color.colorPrimary));
}
}
});
}).snackbar(Snackbar.make(viewPager, "Not connected to internet.", -2)
.setAction("Settings", view -> startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS))));
}

if (!isConfig)
noNet.snackbar(Snackbar.make(viewPager, "Not connected to internet.", -2)
.setAction("Settings", view -> startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS))));
@Override
protected void onResume() {
super.onResume();
appBarLayout.addOnOffsetChangedListener(this);
}

@Override
protected void onPause() {
super.onPause();
appBarLayout.removeOnOffsetChangedListener(this);
}
}
Loading

0 comments on commit 4ffd115

Please sign in to comment.