aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/bienvenidoainternet/baiparser
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/bienvenidoainternet/baiparser')
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java5
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java48
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java6
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java2
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java92
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java9
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java8
7 files changed, 114 insertions, 56 deletions
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
index b91ce2b..575754a 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
@@ -1,7 +1,7 @@
package org.bienvenidoainternet.baiparser;
-import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
public class LicensesActivity extends AppCompatActivity {
@@ -9,7 +9,10 @@ public class LicensesActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ ThemeManager tm = new ThemeManager(this);
+ this.setTheme(tm.getThemeForActivity());
setContentView(R.layout.activity_licenses);
+ getSupportActionBar().setTitle("Acerca de BaI App");
WebView webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("file:///android_asset/html/licenses.html");
}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java
index 9130160..18d2e08 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java
@@ -31,6 +31,7 @@ import com.koushikdutta.ion.Ion;
import org.bienvenidoainternet.baiparser.structure.Board;
import org.bienvenidoainternet.baiparser.structure.BoardItem;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -78,46 +79,25 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ ThemeManager tm = new ThemeManager(this);
+ this.setTheme(tm.getThemeForMainActivity());
if (savedInstanceState != null) {
currentThemeId = savedInstanceState.getInt("currentThemeId");
boardList = savedInstanceState.getParcelableArrayList("boardList");
}
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
- themeId = Integer.valueOf(settings.getString("pref_theme", "1"));
-
if (settings.getString("pref_password", "").isEmpty()){
SharedPreferences.Editor edit = settings.edit();
edit.putString("pref_password", makePassword());
edit.commit();
}
- switch (themeId) {
- case 1:
- currentThemeId = R.style.AppTheme_NoActionBar;
- break;
- case 2:
- currentThemeId = R.style.AppTheme_Dark;
- break;
- case 3:
- currentThemeId = R.style.AppTheme_HeadLine;
- setTheme(R.style.AppTheme_HeadLine_Activity);
- break;
- case 4:
- currentThemeId = R.style.AppTheme_Black;
- setTheme(R.style.AppTheme_Black_Activity);
- break;
- }
-
- themeManager = new ThemeManager(this);
- Log.d("ThemeManager", "isDarkTheme: " + themeManager.isDarkTheme());
-
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Bievenido a internet");
this.setSupportActionBar(toolbar);
-
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
@@ -372,25 +352,25 @@ public class MainActivity extends AppCompatActivity
final SubMenu sub = menu.addSubMenu("Lista de Boards");
Ion.with(getApplicationContext())
.load("http://bienvenidoainternet.org/cgi/api/boards")
- .asJsonObject()
- .setCallback(new FutureCallback<JsonObject>() {
+ .asString()
+ .setCallback(new FutureCallback<String>() {
@Override
- public void onCompleted(Exception e, JsonObject result) {
+ public void onCompleted(Exception e, String result) {
if (e != null) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
- } else {
- JsonArray boards = result.get("boards").getAsJsonArray();
- for (int i = 0; i < boards.size(); i++) {
- try {
- JSONObject board = new JSONObject(boards.get(i).toString());
+ }else {
+ try {
+ JSONArray boards = new JSONObject(result).getJSONArray("boards");
+ for (int i = 0; i < boards.length(); i++) {
+ JSONObject board = boards.getJSONObject(i);
Board parsedBoard = new Board(board.getString("name"), board.getString("dir"), board.getInt("board_type"));
sub.add(parsedBoard.getBoardName());
boardList.add(parsedBoard);
- } catch (JSONException e1) {
- e1.printStackTrace();
- Toast.makeText(getApplicationContext(), "Error parsing JSON", Toast.LENGTH_LONG).show();
}
+ }catch (JSONException e1) {
+ Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
+ e1.printStackTrace();
}
}
}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
index e96868a..350de99 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
@@ -2,12 +2,10 @@ package org.bienvenidoainternet.baiparser;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -45,10 +43,12 @@ public class ResponseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ ThemeManager tm = new ThemeManager(this);
+ this.setTheme(tm.getThemeForActivity());
setContentView(R.layout.activity_response);
+ getSupportActionBar().setTitle("Respondiendo");
settings = PreferenceManager.getDefaultSharedPreferences(this);
password = settings.getString("pref_password", "12345678");
- Log.v("password", password);
if (savedInstanceState != null){
this.theReply = savedInstanceState.getParcelable("theReply");
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
index e8e7df4..eefc5fb 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
@@ -95,6 +95,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ ThemeManager tm = new ThemeManager(this);
+ this.setTheme(tm.getThemeForActivity());
setupActionBar();
getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit();
}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
index 7f0be86..28c0d74 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
@@ -1,26 +1,54 @@
package org.bienvenidoainternet.baiparser;
+import android.app.Activity;
+import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
+import android.preference.PreferenceManager;
+import android.util.Log;
/**
* Created by Renard on 16-03-2016.
*/
public class ThemeManager {
- private MainActivity ac;
private int currentThemeId;
- public ThemeManager(MainActivity ac){
- this.ac = ac;
- this.currentThemeId = ac.getCurrentThemeId();
+ private int prefThemeId;
+ private Activity activity;
+ public ThemeManager(Activity activity){
+ this.activity = activity;
+ setCurrentThemeId();
+ }
+
+ public void setCurrentThemeId(){
+ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
+ int themeId = Integer.valueOf(settings.getString("pref_theme", "1"));
+ prefThemeId = themeId;
+ switch (themeId) {
+ case 1:
+ currentThemeId = R.style.AppTheme_NoActionBar;
+ break;
+ case 2:
+ currentThemeId = R.style.AppTheme_Dark;
+ break;
+ case 3:
+ currentThemeId = R.style.AppTheme_HeadLine;
+// setTheme(R.style.AppTheme_HeadLine_Activity);
+ break;
+ case 4:
+ currentThemeId = R.style.AppTheme_Black;
+// setTheme(R.style.AppTheme_Black_Activity);
+ break;
+ }
+ Log.d("ThemeManager", "isDarkTheme: " + isDarkTheme());
}
public int getSageColor(){
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.sageColor});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.sageColor});
return a.getColor(0, Color.CYAN);
}
public int getMarginColor(){
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.marginColor});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.marginColor});
return a.getColor(0, Color.CYAN);
}
@@ -29,27 +57,69 @@ public class ThemeManager {
}
public int getNameColor() {
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.nameColor});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.nameColor});
return a.getColor(0, Color.CYAN);
}
public int getTripcodeColor() {
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.tripcodeColor});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.tripcodeColor});
return a.getColor(0, Color.CYAN);
}
public int getPrimaryColor(){
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimary});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimary});
return a.getColor(0, Color.CYAN);
}
public int getPrimaryDarkColor(){
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimaryDark});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimaryDark});
return a.getColor(0, Color.CYAN);
}
public boolean isDarkTheme(){
- TypedArray a = ac.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.isDarkTheme});
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.isDarkTheme});
return a.getBoolean(0, false);
}
+ public int getThemeForActivity(){
+ int id = R.style.AppTheme;
+ switch (prefThemeId) {
+ case 1: // pseudoch
+ id = R.style.AppTheme;
+ break;
+ case 2: // nightmode
+ id = R.style.AppTheme;
+ break;
+ case 3: // photon
+ id = R.style.AppTheme_HeadLineActionBar;
+ break;
+ case 4: // tomorrow
+ id = R.style.AppTheme_BlackActionBar;
+ break;
+ }
+ return id;
+ }
+
+ public int getThemeForMainActivity(){
+ int id = R.style.AppTheme_NoActionBar;
+ switch (prefThemeId) {
+ case 1: // pseudoch
+ id = R.style.AppTheme_NoActionBar;
+ break;
+ case 2: // nightmode
+ id = R.style.AppTheme_NoActionBar;
+ break;
+ case 3: // photon
+ id = R.style.AppTheme_HeadLineActionBar_NoActionBar;
+ break;
+ case 4: // tomorrow
+ id = R.style.AppTheme_BlackActionBar_NoActionBar;
+ break;
+ }
+ return id;
+ }
+
+
+ public int getCurrentThemeId() {
+ return currentThemeId;
+ }
}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java
index 85cd891..7a85c1f 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java
@@ -228,8 +228,15 @@ public class ThreadListAdapter extends ArrayAdapter<BoardItem>{
txtReplies.setVisibility(boardItem.isReply ? View.GONE : View.VISIBLE);
txtReplies.setText(boardItem.getTotalReplies() + " respuestas " + (boardItem.getTotalFiles() == 0 ? "" : ", " + boardItem.getTotalFiles() + " archivos"));
+ String fileExt = "";
+ if (!boardItem.getFile().isEmpty()){
+ String[] pathSplit = boardItem.getFile().split("\\.");
+ if (pathSplit.length != 0){
+ fileExt = pathSplit[1].toUpperCase();
+ }
+ }
txtFileInfo.setVisibility(boardItem.getThumb().isEmpty() ? View.GONE : View.VISIBLE);
- txtFileInfo.setText((boardItem.getFileSize() / 1024) + " KB " + boardItem.getThumbHeight() + "x" + boardItem.getThumbWidth());
+ txtFileInfo.setText(fileExt + " " + (boardItem.getFileSize() / 1024) + " KB " + boardItem.getThumbHeight() + "x" + boardItem.getThumbWidth());
// Trasnparentar items con sage
if (convertView != null){
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
index 9d140ec..8dc1262 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
@@ -14,9 +14,6 @@ import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.Toast;
-import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
-
-import org.bienvenidoainternet.baiparser.structure.BoardItem;
import org.bienvenidoainternet.baiparser.structure.BoardItemFile;
import java.io.File;
@@ -27,7 +24,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import layout.FragmentImage;
-import pl.droidsonroids.gif.GifImageView;
public class ViewerActivity extends AppCompatActivity implements FragmentImage.OnFragmentInteractionListener {
private static final String EXTRA_FILELIST = "fileList", EXTRA_RELATIVEPOSITION = "position";
@@ -54,7 +50,6 @@ public class ViewerActivity extends AppCompatActivity implements FragmentImage.O
pagerAdapter.addFragment(FragmentImage.newInstance(fileList.get(i)));
}
imagePager.setAdapter(pagerAdapter);
- imagePager.setCurrentItem(relativePosition);
imagePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@@ -63,7 +58,7 @@ public class ViewerActivity extends AppCompatActivity implements FragmentImage.O
@Override
public void onPageSelected(int position) {
- getSupportActionBar().setSubtitle(fileList.get(position).file);
+ getSupportActionBar().setSubtitle("(" + (position + 1) + " / " + fileList.size() + ") " + fileList.get(position).file);
}
@Override
@@ -71,6 +66,7 @@ public class ViewerActivity extends AppCompatActivity implements FragmentImage.O
}
});
+ imagePager.setCurrentItem(relativePosition);
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}