Skip to content

Commit

Permalink
NClientV2 1.7.7
Browse files Browse the repository at this point in the history
+ Added new SearchActivity
* Check for updates from API 16
* Bug fixes
  • Loading branch information
Dar9586 committed Feb 14, 2019
1 parent 1cd0abb commit 0e573c7
Show file tree
Hide file tree
Showing 20 changed files with 620 additions and 51 deletions.
8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.dar.nclientv2"
minSdkVersion 14
targetSdkVersion 28
versionCode 176
versionName "1.7.6"
versionCode 177
versionName "1.7.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

Expand All @@ -30,7 +30,7 @@ android {
}

dependencies {
def supportVersion='1.0.0'
def supportVersion = '1.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.legacy:legacy-support-v4:$supportVersion"
Expand All @@ -46,4 +46,6 @@ dependencies {
implementation 'org.jsoup:jsoup:1.11.3'

implementation "ch.acra:acra-core:5.1.3"
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
}
17 changes: 16 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/LightTheme">
<activity android:name=".SearchActivity"
android:windowSoftInputMode="stateAlwaysVisible">
</activity>
<activity
android:hardwareAccelerated="true"
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:theme="@style/DarkTheme">
<intent-filter>
Expand All @@ -40,6 +43,7 @@
<data android:pathPrefix="/group/" />
<data android:pathPrefix="/language/" />
<data android:pathPrefix="/category/" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -57,7 +61,9 @@
<data
android:host="nhentai.net"
android:pathPattern="/g/.*" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Expand Down Expand Up @@ -102,7 +108,9 @@
<data android:pathPrefix="/characters" />
<data android:pathPrefix="/parodies" />
<data android:pathPrefix="/groups" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Expand All @@ -118,7 +126,9 @@
<data android:scheme="https" />
<data android:host="nhentai.net" />
<data android:pathPrefix="/random" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Expand All @@ -132,7 +142,9 @@
<data android:scheme="https" />
<data android:host="nhentai.net" />
<data android:pathPrefix="/favorites" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Expand All @@ -159,12 +171,15 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.dar.nclientv2.MainActivity" />

<intent-filter>
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="nhentai.net" />
<data android:pathPrefix="/login" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Expand Down
101 changes: 65 additions & 36 deletions app/src/main/java/com/dar/nclientv2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
Expand All @@ -12,7 +13,6 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.dar.nclientv2.api.Inspector;
import com.dar.nclientv2.api.components.Tag;
Expand All @@ -35,9 +35,9 @@
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
Expand All @@ -51,6 +51,7 @@ public class MainActivity extends BaseActivity
private Tag tag;
private int related=-1;
private boolean tagFromURL=false;
private static boolean firstTime=true;
public void setInspector(Inspector inspector) {
this.inspector = inspector;
}
Expand Down Expand Up @@ -106,12 +107,10 @@ protected void onCreate(Bundle savedInstanceState) {
navigationView = findViewById(R.id.nav_view);
changeNavigationImage(navigationView);
navigationView.setNavigationItemSelectedListener(this);

navigationView.getMenu().findItem(R.id.online_favorite_manager).setVisible(com.dar.nclientv2.settings.Login.isLogged());
navigationView.getMenu().findItem(R.id.action_login).setTitle(com.dar.nclientv2.settings.Login.isLogged()?R.string.logout:R.string.login);
recycler=findViewById(R.id.recycler);
refresher=findViewById(R.id.refresher);
prepareUpdateIcon();
recycler.setHasFixedSize(true);
recycler.setItemViewCacheSize(24);
recycler.addOnScrollListener(new RecyclerView.OnScrollListener(){
Expand Down Expand Up @@ -160,7 +159,10 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy){
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
toggle.setDrawerIndicatorEnabled(false);
} else new Inspector(this,1,"",ApiRequestType.BYALL);
if(Global.shouldCheckForUpdates(this))new VersionChecker(this,true);
if(firstTime){
if(Global.shouldCheckForUpdates(this))new VersionChecker(this,true);
firstTime=false;
}
}

private void changeNavigationImage(NavigationView navigationView) {
Expand All @@ -176,33 +178,18 @@ protected void onDestroy(){
super.onDestroy();
}

private void prepareUpdateIcon(){
if(Global.getOnlyLanguage()==null)Global.updateOnlyLanguage(this,Language.UNKNOWN);
else{
switch (Global.getOnlyLanguage()){
case ENGLISH:Global.updateOnlyLanguage(this,null);break;
case JAPANESE:Global.updateOnlyLanguage(this,Language.ENGLISH);break;
case CHINESE:Global.updateOnlyLanguage(this,Language.JAPANESE);break;
case UNKNOWN:Global.updateOnlyLanguage(this,Language.CHINESE);break;
}
}
}
private void updateLanguageIcon(MenuItem item,boolean update){
private void updateLanguageIcon(MenuItem item){
//ALL,ENGLISH;JAPANESE;CHINESE;OTHER

if(Global.getOnlyLanguage()==null){
Global.updateOnlyLanguage(this,Language.ENGLISH);
item.setTitle(R.string.only_english);
item.setIcon(R.drawable.ic_gbbw);
}
if(Global.getOnlyLanguage()==null) Global.updateOnlyLanguage(this,Language.ENGLISH);
else
switch (Global.getOnlyLanguage()){
case ENGLISH:Global.updateOnlyLanguage(this, Language.JAPANESE);item.setTitle(R.string.only_japanese);item.setIcon(R.drawable.ic_jpbw);break;
case JAPANESE:Global.updateOnlyLanguage(this, Language.CHINESE);item.setTitle(R.string.only_chinese);item.setIcon(R.drawable.ic_cnbw);break;
case CHINESE:Global.updateOnlyLanguage(this, Language.UNKNOWN);item.setTitle(R.string.only_other);item.setIcon(R.drawable.ic_help);break;
case UNKNOWN:Global.updateOnlyLanguage(this, null);item.setTitle(R.string.all_languages);item.setIcon(R.drawable.ic_world);break;
case ENGLISH:Global.updateOnlyLanguage(this, Language.JAPANESE);break;
case JAPANESE:Global.updateOnlyLanguage(this, Language.CHINESE);break;
case CHINESE:Global.updateOnlyLanguage(this, Language.UNKNOWN);break;
case UNKNOWN:Global.updateOnlyLanguage(this, null);break;
}
if(update)new Inspector(MainActivity.this,Inspector.getActualPage(),Inspector.getActualQuery(),Inspector.getActualRequestType());
new Inspector(MainActivity.this,Inspector.getActualPage(),Inspector.getActualQuery(),Inspector.getActualRequestType());
Global.setTint(item.getIcon());
}
@Override
Expand Down Expand Up @@ -259,7 +246,6 @@ private class Setting{
}
}
private void removeQuery(){
searchView.setQuery("",false);
getSupportActionBar().setTitle(R.string.app_name);
if(related!=-1){
new Inspector(this,1,""+related,ApiRequestType.RELATED);
Expand Down Expand Up @@ -298,14 +284,13 @@ protected void onResume() {
}
invalidateOptionsMenu();
}
private SearchView searchView;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
menu.findItem(R.id.by_popular).setIcon(Global.isByPopular()?R.drawable.ic_star_border:R.drawable.ic_access_time);
menu.findItem(R.id.by_popular).setTitle(Global.isByPopular()?R.string.sort_by_popular:R.string.sort_by_latest);
updateLanguageIcon(menu.findItem(R.id.only_language),false);
showLanguageIcon(menu.findItem(R.id.only_language));

if(tag!=null||related!=-1){
if(tag!=null){
Expand All @@ -323,12 +308,12 @@ public boolean onCreateOptionsMenu(Menu menu) {
}
Global.setTint(menu.findItem(R.id.open_browser).getIcon());
Global.setTint(menu.findItem(R.id.by_popular).getIcon());
searchView =(SearchView)menu.findItem(R.id.search).getActionView();
if(related!=-1){
menu.findItem(R.id.search).setVisible(false);
return true;
}
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
menu.findItem(R.id.search).setActionView(null);
/*searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if(query.length()==0)return true;
Expand All @@ -352,12 +337,25 @@ public boolean onQueryTextSubmit(String query) {
public boolean onQueryTextChange(String newText) {
return true;
}
});
ImageView closeButton = searchView.findViewById(R.id.search_close_btn);
closeButton.setOnClickListener(v -> removeQuery());
});*/
return true;
}

private void showLanguageIcon(MenuItem item) {
if(Global.getOnlyLanguage()==null){
item.setTitle(R.string.all_languages);item.setIcon(R.drawable.ic_world);

}
else
switch (Global.getOnlyLanguage()){
case JAPANESE:item.setTitle(R.string.only_japanese);item.setIcon(R.drawable.ic_jpbw);break;
case CHINESE:item.setTitle(R.string.only_chinese);item.setIcon(R.drawable.ic_cnbw);break;
case UNKNOWN:item.setTitle(R.string.only_other);item.setIcon(R.drawable.ic_help);break;
case ENGLISH:item.setTitle(R.string.only_english);item.setIcon(R.drawable.ic_gbbw);break;
}
Global.setTint(item.getIcon());
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand All @@ -371,7 +369,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
item.setTitle(Global.isByPopular()?R.string.sort_by_popular:R.string.sort_by_latest);
Global.setTint(item.getIcon());
new Inspector(this,1,Inspector.getActualQuery(),Inspector.getActualRequestType());break;
case R.id.only_language:updateLanguageIcon(item,true);break;
case R.id.only_language:updateLanguageIcon(item);showLanguageIcon(item); break;
case R.id.search:
i=new Intent(this,SearchActivity.class);
startActivityForResult(i,1);
break;
case R.id.open_browser:
if(inspector!=null) {
i = new Intent(Intent.ACTION_VIEW);
Expand All @@ -393,6 +395,29 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if(requestCode==1&&resultCode== Activity.RESULT_OK){
manageQuery(data.getStringExtra("query"));
}
super.onActivityResult(requestCode, resultCode, data);
}
private void manageQuery(String query){
if(query.length()==0)return;
try {
if (tag == null && related == -1) {
int id=Integer.parseInt(query);
if(id>0&&id<=Global.getMaxId()){
new Inspector(MainActivity.this, -1, "" + id, ApiRequestType.BYSINGLE);
return;
}
}
}catch (NumberFormatException ignore){}
query=query.trim();
getSupportActionBar().setTitle(query+(tag!=null?' '+tag.getName():""));
new Inspector(MainActivity.this,1,query+(tag!=null?(' '+tag.toQueryTag(TagStatus.DEFAULT)):""),ApiRequestType.BYSEARCH);
}

private void showLogoutForm() {
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_exit_to_app).setTitle(R.string.logout).setMessage(R.string.are_you_sure);
Expand Down Expand Up @@ -420,6 +445,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
startActivity(intent);
}
break;
case R.id.search:
intent=new Intent(this,SearchActivity.class);
startActivity(intent);
break;
case R.id.favorite_manager:
intent=new Intent(this,FavoriteActivity.class);
startActivity(intent);
Expand Down
Loading

0 comments on commit 0e573c7

Please sign in to comment.