From a5f9e1088f94890c44f70a2ebd4c38d7e86f2adf Mon Sep 17 00:00:00 2001
From: Renard
Date: Tue, 26 Apr 2016 15:59:17 -0300
Subject: packageID, gradle version fix, jsoup license.
---
.../app/AppCompatPreferenceActivity.java | 109 +++++
.../app/CustomFragmentPagerAdapter.java | 67 +++
.../bienvenidoainternet/app/LicensesActivity.java | 37 ++
.../org/bienvenidoainternet/app/MainActivity.java | 482 ++++++++++++++++++++
.../bienvenidoainternet/app/RecentPostAdapter.java | 105 +++++
.../bienvenidoainternet/app/ResponseActivity.java | 368 ++++++++++++++++
.../bienvenidoainternet/app/SettingsActivity.java | 204 +++++++++
.../org/bienvenidoainternet/app/ThemeManager.java | 140 ++++++
.../bienvenidoainternet/app/ThreadListAdapter.java | 337 ++++++++++++++
.../bienvenidoainternet/app/ViewerActivity.java | 137 ++++++
.../bienvenidoainternet/app/structure/Board.java | 87 ++++
.../app/structure/BoardItem.java | 352 +++++++++++++++
.../app/structure/BoardItemFile.java | 63 +++
.../bienvenidoainternet/app/structure/ReplyID.java | 68 +++
.../baiparser/AppCompatPreferenceActivity.java | 109 -----
.../baiparser/CustomFragmentPagerAdapter.java | 67 ---
.../baiparser/LicensesActivity.java | 37 --
.../baiparser/MainActivity.java | 489 ---------------------
.../baiparser/RecentPostAdapter.java | 105 -----
.../baiparser/ResponseActivity.java | 370 ----------------
.../baiparser/SettingsActivity.java | 205 ---------
.../baiparser/ThemeManager.java | 140 ------
.../baiparser/ThreadListAdapter.java | 337 --------------
.../baiparser/ViewerActivity.java | 137 ------
.../baiparser/structure/Board.java | 87 ----
.../baiparser/structure/BoardItem.java | 353 ---------------
.../baiparser/structure/BoardItemFile.java | 63 ---
.../baiparser/structure/ReplyID.java | 68 ---
28 files changed, 2556 insertions(+), 2567 deletions(-)
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/AppCompatPreferenceActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/CustomFragmentPagerAdapter.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/LicensesActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/MainActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/RecentPostAdapter.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/ResponseActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/SettingsActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/ThemeManager.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/ThreadListAdapter.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/ViewerActivity.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/structure/Board.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/structure/BoardItem.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/structure/BoardItemFile.java
create mode 100644 app/src/main/java/org/bienvenidoainternet/app/structure/ReplyID.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/AppCompatPreferenceActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/CustomFragmentPagerAdapter.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/RecentPostAdapter.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItemFile.java
delete mode 100644 app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java
(limited to 'app/src/main/java/org')
diff --git a/app/src/main/java/org/bienvenidoainternet/app/AppCompatPreferenceActivity.java b/app/src/main/java/org/bienvenidoainternet/app/AppCompatPreferenceActivity.java
new file mode 100644
index 0000000..1f916ad
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/AppCompatPreferenceActivity.java
@@ -0,0 +1,109 @@
+package org.bienvenidoainternet.app;
+
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.support.annotation.LayoutRes;
+import android.support.annotation.Nullable;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatDelegate;
+import android.support.v7.widget.Toolbar;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
+ * to be used with AppCompat.
+ */
+public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
+
+ private AppCompatDelegate mDelegate;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ getDelegate().installViewFactory();
+ getDelegate().onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ getDelegate().onPostCreate(savedInstanceState);
+ }
+
+ public ActionBar getSupportActionBar() {
+ return getDelegate().getSupportActionBar();
+ }
+
+ public void setSupportActionBar(@Nullable Toolbar toolbar) {
+ getDelegate().setSupportActionBar(toolbar);
+ }
+
+ @Override
+ public MenuInflater getMenuInflater() {
+ return getDelegate().getMenuInflater();
+ }
+
+ @Override
+ public void setContentView(@LayoutRes int layoutResID) {
+ getDelegate().setContentView(layoutResID);
+ }
+
+ @Override
+ public void setContentView(View view) {
+ getDelegate().setContentView(view);
+ }
+
+ @Override
+ public void setContentView(View view, ViewGroup.LayoutParams params) {
+ getDelegate().setContentView(view, params);
+ }
+
+ @Override
+ public void addContentView(View view, ViewGroup.LayoutParams params) {
+ getDelegate().addContentView(view, params);
+ }
+
+ @Override
+ protected void onPostResume() {
+ super.onPostResume();
+ getDelegate().onPostResume();
+ }
+
+ @Override
+ protected void onTitleChanged(CharSequence title, int color) {
+ super.onTitleChanged(title, color);
+ getDelegate().setTitle(title);
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ getDelegate().onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ getDelegate().onStop();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ getDelegate().onDestroy();
+ }
+
+ public void invalidateOptionsMenu() {
+ getDelegate().invalidateOptionsMenu();
+ }
+
+ private AppCompatDelegate getDelegate() {
+ if (mDelegate == null) {
+ mDelegate = AppCompatDelegate.create(this, null);
+ }
+ return mDelegate;
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/CustomFragmentPagerAdapter.java b/app/src/main/java/org/bienvenidoainternet/app/CustomFragmentPagerAdapter.java
new file mode 100644
index 0000000..f760cca
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/CustomFragmentPagerAdapter.java
@@ -0,0 +1,67 @@
+package org.bienvenidoainternet.app;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class CustomFragmentPagerAdapter extends FragmentPagerAdapter {
+
+ // List of fragments which are going to set in the view pager widget
+ List fragments;
+
+ /**
+ * Constructor
+ *
+ * @param fm
+ * interface for interacting with Fragment objects inside of an
+ * Activity
+ */
+ public CustomFragmentPagerAdapter(FragmentManager fm) {
+ super(fm);
+ this.fragments = new ArrayList();
+ }
+
+ /**
+ * Add a new fragment in the list.
+ *
+ * @param fragment
+ * a new fragment
+ */
+ public void addFragment(Fragment fragment) {
+ this.fragments.add(fragment);
+ }
+
+ @Override
+ public Fragment getItem(int arg0) {
+ return this.fragments.get(arg0);
+ }
+
+ @Override
+ public int getCount() {
+ return this.fragments.size();
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/bienvenidoainternet/app/LicensesActivity.java b/app/src/main/java/org/bienvenidoainternet/app/LicensesActivity.java
new file mode 100644
index 0000000..1924511
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/LicensesActivity.java
@@ -0,0 +1,37 @@
+package org.bienvenidoainternet.app;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.webkit.WebView;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+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/app/MainActivity.java b/app/src/main/java/org/bienvenidoainternet/app/MainActivity.java
new file mode 100644
index 0000000..0d266fc
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/MainActivity.java
@@ -0,0 +1,482 @@
+package org.bienvenidoainternet.app;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.design.widget.FloatingActionButton;
+import android.support.design.widget.NavigationView;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.view.ViewPager;
+import android.support.v4.widget.DrawerLayout;
+import android.support.v7.app.ActionBarDrawerToggle;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.SubMenu;
+import android.view.View;
+import android.widget.BaseAdapter;
+import android.widget.HeaderViewListAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import com.koushikdutta.async.future.FutureCallback;
+import com.koushikdutta.ion.Ion;
+
+import org.bienvenidoainternet.app.structure.Board;
+import org.bienvenidoainternet.app.structure.BoardItem;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import layout.FragmentBoardItemList;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class MainActivity extends AppCompatActivity
+ implements NavigationView.OnNavigationItemSelectedListener, FragmentBoardItemList.OnFragmentInteractionListener {
+ private ViewPager pager; // variable del ViewPager
+ CustomFragmentPagerAdapter pagerAdapter; // Adaptador del ViewPager
+ NavigationView navigationView;
+ DrawerLayout drawer;
+ FloatingActionButton fab;
+ public ThemeManager themeManager;
+ FragmentBoardItemList childFragment; // Segunda página del ViewPager, se muestra un solo hilo (selecionado del catálogo)
+ FragmentBoardItemList mainFragment; // Primera página del ViewPager, se muestra una lista de hilos. (catálogo)
+ Toolbar toolbar = null;
+ public int currentThemeId = 0, themeId = 0; // Id del recurso, Id del tema
+ public ArrayList boardList = new ArrayList<>();
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putInt("currentThemeId", currentThemeId);
+ outState.putInt("themeId", themeId);
+ outState.putParcelableArrayList("boardList", boardList);
+ if (getSupportFragmentManager().getFragments() != null) {
+ if (getSupportFragmentManager().getFragments().size() != 0) {
+ try {
+ getSupportFragmentManager().putFragment(outState, "mainFragment", mainFragment);
+ getSupportFragmentManager().putFragment(outState, "childFragment", childFragment);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public int getCurrentThemeId() {
+ return currentThemeId;
+ }
+
+ @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);
+ if (settings.getString("pref_password", "").isEmpty()){
+ SharedPreferences.Editor edit = settings.edit();
+ edit.putString("pref_password", makePassword());
+ edit.commit();
+ }
+
+ 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
+ public void onClick(View view) {
+ if (pager.getCurrentItem() == 0){
+ if (!mainFragment.getMode() && mainFragment.currentBoard != null){
+ Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
+ Bundle b = new Bundle();
+ BoardItem temp = new BoardItem();
+ temp.setParentBoard(mainFragment.currentBoard);
+ b.putParcelable("theReply", temp);
+ b.putBoolean("quoting", false);
+ b.putBoolean("newthread", true);
+ in.putExtras(b);
+ startActivity(in);
+ }
+ }else{
+ if (childFragment.currentBoard != null) {
+ if (!childFragment.boardItems.isEmpty()) {
+ try {
+ Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
+ Bundle b = new Bundle();
+ BoardItem reply = childFragment.boardItems.get(0);
+ if (!reply.isLocked) {
+ b.putParcelable("theReply", reply);
+ b.putBoolean("quoting", false);
+ b.putBoolean("newthread", false);
+ in.putExtras(b);
+ startActivity(in);
+ }else{
+ Toast.makeText(getApplicationContext(), "Error: Este hilo está cerrado", Toast.LENGTH_LONG).show();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ });
+ fab.setVisibility(View.GONE);
+
+ drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
+ this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
+ drawer.setDrawerListener(toggle);
+ toggle.syncState();
+
+ navigationView = (NavigationView) findViewById(R.id.nav_view);
+ navigationView.setNavigationItemSelectedListener(this);
+
+ if (savedInstanceState != null) {
+ mainFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState, "mainFragment");
+ childFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState, "childFragment");
+ } else {
+ mainFragment = FragmentBoardItemList.newInstance(true, null, null);
+ childFragment = FragmentBoardItemList.newInstance(false, null, null);
+ }
+
+ this.pager = (ViewPager) findViewById(R.id.pager);
+ this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
+ pagerAdapter.addFragment(mainFragment);
+ pagerAdapter.addFragment(childFragment);
+ this.pager.setAdapter(pagerAdapter);
+
+ pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ if (position == 0){
+ fab.setImageResource(R.drawable.ic_action_add);
+ if (mainFragment.currentBoard != null) {
+ toolbar.setTitle("Catálogo");
+ toolbar.setSubtitle(mainFragment.currentBoard.getBoardName());
+ }
+ if (mainFragment.getMode()){
+ toolbar.setTitle("Post recientes");
+ toolbar.setSubtitle("");
+ }
+ if (mainFragment.getMode()){
+ fab.hide();
+ }else{
+ fab.show();
+ }
+ }else if (position == 1){
+ fab.setImageResource(R.drawable.ic_edit);
+ if (childFragment.currentBoard != null) {
+ toolbar.setTitle(childFragment.currentBoard.getBoardName());
+ if (!childFragment.boardItems.isEmpty()){
+ toolbar.setSubtitle(childFragment.boardItems.get(0).getSubject());
+ }
+ fab.show();
+ }
+ }
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+
+ }
+ });
+
+ if (boardList.isEmpty()){
+ getBoardList();
+ }else{
+ Menu menu = navigationView.getMenu();
+ SubMenu sub = menu.addSubMenu("Lista de Boards");
+ for (Board b : boardList) {
+ sub.add(b.getBoardName());
+ }
+ refreshNavigator();
+ }
+
+ if (tm.isDarkTheme()){
+ navigationView.setBackgroundColor(0xFF888888);
+ }
+ }
+
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == 1) {
+ if(resultCode == Activity.RESULT_OK){
+ boolean result = data.getBooleanExtra("result", false);
+ if (result){
+ this.recreate();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (this.pager.getCurrentItem() == 0) {
+ super.onBackPressed();
+ } else {
+ this.pager.setCurrentItem(this.pager.getCurrentItem() - 1);
+ return;
+ }
+ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ if (drawer.isDrawerOpen(GravityCompat.START)) {
+ drawer.closeDrawer(GravityCompat.START);
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ switch (id) {
+ case R.id.action_exit:
+ System.exit(0);
+ break;
+ case R.id.action_refresh:
+ if (pager.getCurrentItem() == 0) {
+ mainFragment.refresh();
+ } else {
+ childFragment.refresh();
+ }
+ if (boardList.isEmpty()){
+ getBoardList();
+ }
+ break;
+ case R.id.action_settings:
+ Intent in2 = new Intent(getApplicationContext(), SettingsActivity.class);
+ startActivityForResult(in2, 1);
+ break;
+ case R.id.action_to_bot:
+ if (pager.getCurrentItem() == 0) {
+ mainFragment.scrollToBotton();
+ } else {
+ childFragment.scrollToBotton();
+ }
+ break;
+ case R.id.action_to_top:
+ if (pager.getCurrentItem() == 0) {
+ mainFragment.scrollToTop();
+ } else {
+ childFragment.scrollToTop();
+ }
+ break;
+ case R.id.action_about:
+ startActivity(new Intent(getApplicationContext(), LicensesActivity.class));
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @SuppressWarnings("StatementWithEmptyBody")
+ @Override
+ public boolean onNavigationItemSelected(MenuItem item) {
+ // Handle navigation view item clicks here.
+ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ drawer.closeDrawer(GravityCompat.START);
+ int id = item.getItemId();
+ toolbar.setSubtitle(item.getTitle());
+ if (id == R.id.nav_recent_post){
+ toolbar.setTitle("Post recientes");
+ toolbar.setSubtitle("");
+ pager.setCurrentItem(0);
+ mainFragment.loadRecentPost();
+ }
+ for (Board b : boardList){
+ if (b.getBoardName() == item.getTitle()){
+ System.out.println("Updating mainfragment to " + b.getBoardName() + " d: " + b.getBoardDir());
+ mainFragment.setCatalogMode();
+ mainFragment.updateBoardItems(b, null);
+ pager.setCurrentItem(0);
+ navigationView.getMenu().findItem(R.id.nav_recent_post).setChecked(false);
+ }
+ }
+ return true;
+ }
+
+ public Board getBoardFromDir(String dir){
+ for (Board b : boardList){
+ if (b.getBoardDir().equals(dir)){
+ return b;
+ }
+ }
+ System.out.println("[MainActivity] Board not found " + dir);
+ return null;
+ }
+
+
+ @Override
+ public void onFragmentInteraction(Uri uri) {
+
+ }
+
+ @Override
+ public void showThread(Board board, BoardItem thread) {
+ childFragment.updateBoardItems(board, thread);
+ pager.setCurrentItem(1);
+ }
+
+
+ @Override
+ public void updateToolbar(Board cBoard, BoardItem btem) {
+ if (pager.getCurrentItem() == 1){
+ toolbar.setTitle(cBoard.getBoardName());
+ toolbar.setSubtitle(btem.getSubject());
+ }
+ }
+
+ @Override
+ public void updateToolbar(String s) {
+ toolbar.setTitle(s);
+ toolbar.setSubtitle("");
+ }
+
+ @Override
+ public void hideActionButton() {
+ if (pager.getCurrentItem() == 1){
+ fab.hide();
+ }
+ }
+
+ @Override
+ public void showActionButton() {
+ if (pager.getCurrentItem() == 1){
+ fab.show();
+ }
+ }
+
+ @Override
+ public void onThreadList() {
+ if (pager.getCurrentItem() == 0){
+ getSupportActionBar().setTitle("Catálogo");
+ getSupportActionBar().setSubtitle(mainFragment.currentBoard.getBoardName());
+ fab.show();
+ }
+ }
+
+ @Override
+ public void onThread() {
+ if (pager.getCurrentItem() == 1){
+ getSupportActionBar().setTitle(childFragment.currentBoard.getBoardName());
+ getSupportActionBar().setSubtitle(childFragment.boardItems.get(0).getSubject());
+ }
+ }
+
+ @Override
+ public void onRecentPosts() {
+ if (pager.getCurrentItem() == 0){
+ getSupportActionBar().setTitle("Post recientes");
+ getSupportActionBar().setSubtitle("");
+ fab.hide();
+ }
+ }
+
+ private void getBoardList(){
+ Menu menu = navigationView.getMenu();
+ final SubMenu sub = menu.addSubMenu("Lista de Boards");
+ Ion.with(getApplicationContext())
+ .load("http://bienvenidoainternet.org/cgi/api/boards")
+ .asString()
+ .setCallback(new FutureCallback() {
+ @Override
+ public void onCompleted(Exception e, String result) {
+ if (e != null) {
+ e.printStackTrace();
+ Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
+ }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"), board.getInt("allow_image_replies") == 1 ? true : false);
+ sub.add(parsedBoard.getBoardName());
+ boardList.add(parsedBoard);
+ }
+ }catch (JSONException e1) {
+ Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
+ e1.printStackTrace();
+ }
+ }
+ }
+ });
+ refreshNavigator();
+ }
+
+ public void refreshNavigator(){
+ for (int i = 0, count = navigationView.getChildCount(); i < count; i++) {
+ final View child = navigationView.getChildAt(i);
+ if (child != null && child instanceof ListView) {
+ final ListView menuView = (ListView) child;
+ final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
+ final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
+ wrapped.notifyDataSetChanged();
+ }
+ }
+ }
+
+ /*
+ Crea una secuencia de caracteres de 8 digitos aleatorios (incluye mayusculas, minisculas y numeros).
+ */
+ public String makePassword(){
+ Random r = new Random();
+ String rnd = "";
+ for (int i = 0; i < 8; i++){
+ int a = r.nextInt(3);
+ char b;
+ if (a == 0){
+ b = (char)(66 + r.nextInt(25));
+ }else if (a == 1){
+ b = (char)(97 + r.nextInt(25));
+ }else{
+ b = (char) (48 + r.nextInt(9));
+ }
+ rnd = rnd + b;
+ }
+ return rnd;
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/RecentPostAdapter.java b/app/src/main/java/org/bienvenidoainternet/app/RecentPostAdapter.java
new file mode 100644
index 0000000..86c4b92
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/RecentPostAdapter.java
@@ -0,0 +1,105 @@
+package org.bienvenidoainternet.app;
+
+import android.content.Context;
+import android.text.Html;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import org.bienvenidoainternet.app.structure.BoardItem;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class RecentPostAdapter extends ArrayAdapter {
+
+ public RecentPostAdapter(Context context, List objects) {
+ super(context, 0, objects);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LayoutInflater inflater = (LayoutInflater)getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View listItemView = convertView;
+ if (null == convertView) {
+ listItemView = inflater.inflate(
+ R.layout.recentpost_item,
+ parent,
+ false);
+ }
+ final BoardItem postItem = getItem(position);
+ TextView rp_message = (TextView) listItemView.findViewById(R.id.rp_message);
+ TextView rp_title = (TextView) listItemView.findViewById(R.id.rp_title);
+ TextView rp_timediff = (TextView) listItemView.findViewById(R.id.rp_timediff);
+ if (postItem.getParentBoard() != null){
+ rp_title.setText(postItem.getParentBoard().getBoardName() + ": " + postItem.getSubject());
+ }else{
+ rp_title.setText(postItem.getSubject());
+ }
+ rp_message.setText(Html.fromHtml(postItem.getMessage()));
+ Map timeDiff = computeDiff(new Date(postItem.getTimeStamp() * 1000L), new Date(System.currentTimeMillis()));
+ String strTimeDiff = "";
+ if (timeDiff.get(TimeUnit.SECONDS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.SECONDS) + (timeDiff.get(TimeUnit.SECONDS) == 1 ? " segundo" : " segundos");
+ }
+
+ if (timeDiff.get(TimeUnit.MINUTES) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.MINUTES) + (timeDiff.get(TimeUnit.MINUTES) == 1 ? " minuto" : " minutos");
+ }
+
+ if (timeDiff.get(TimeUnit.HOURS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.HOURS) + (timeDiff.get(TimeUnit.HOURS) == 1 ? " hora" : " horas");
+ }
+
+ if (timeDiff.get(TimeUnit.DAYS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.DAYS) + (timeDiff.get(TimeUnit.DAYS) == 1 ? " día" : " días");
+ }
+ rp_timediff.setText(strTimeDiff);
+
+
+ return listItemView;
+ }
+
+
+ public static Map computeDiff(Date date1, Date date2) {
+ long diffInMillies = date2.getTime() - date1.getTime();
+ List units = new ArrayList(EnumSet.allOf(TimeUnit.class));
+ Collections.reverse(units);
+ Map result = new LinkedHashMap();
+ long milliesRest = diffInMillies;
+ for ( TimeUnit unit : units ) {
+ long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
+ long diffInMilliesForUnit = unit.toMillis(diff);
+ milliesRest = milliesRest - diffInMilliesForUnit;
+ result.put(unit,diff);
+ }
+ return result;
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/ResponseActivity.java b/app/src/main/java/org/bienvenidoainternet/app/ResponseActivity.java
new file mode 100644
index 0000000..74ac04b
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/ResponseActivity.java
@@ -0,0 +1,368 @@
+package org.bienvenidoainternet.app;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.koushikdutta.async.future.FutureCallback;
+import com.koushikdutta.ion.Ion;
+
+import org.bienvenidoainternet.app.structure.BoardItem;
+
+import java.io.File;
+
+import utils.ContentProviderUtils;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class ResponseActivity extends AppCompatActivity {
+
+ private BoardItem theReply = null;
+ private SharedPreferences settings;
+ private String password;
+ private String selectedFile = "";
+ private final int PICK_IMAGE = 1;
+ private boolean quoting = false, newthread = false;
+ EditText filePath;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ThemeManager tm = new ThemeManager(this);
+ this.setTheme(tm.getThemeForActivity());
+ setContentView(R.layout.activity_response);
+
+ settings = PreferenceManager.getDefaultSharedPreferences(this);
+ password = settings.getString("pref_password", "12345678");
+
+ if (savedInstanceState != null){
+ this.theReply = savedInstanceState.getParcelable("theReply");
+ this.quoting = savedInstanceState.getBoolean("quoting");
+ this.newthread = savedInstanceState.getBoolean("newthread");
+ }
+ if (getIntent().getExtras() != null){
+ this.theReply = getIntent().getParcelableExtra("theReply");
+ this.quoting = getIntent().getBooleanExtra("quoting", false);
+ this.newthread = getIntent().getBooleanExtra("newthread", false);
+ }
+
+ if (newthread){
+ getSupportActionBar().setTitle("Nuevo hilo");
+ getSupportActionBar().setSubtitle(theReply.getParentBoard().getBoardName());
+ }else{
+ getSupportActionBar().setTitle("Respondiendo");
+ }
+
+ TextView txtFilePath = (TextView) findViewById(R.id.txtFilePath);
+ Button btnSelectFile = (Button) findViewById(R.id.btnSelectFiles);
+ TextView txtThreadSubject = (TextView) findViewById(R.id.txtThreadSubject);
+
+ txtThreadSubject.setVisibility(newthread ? View.VISIBLE : View.GONE);
+
+ if (theReply != null && quoting){
+ TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
+ if (theReply.getParentBoard().getBoardType() == 1){ // BBS
+ txtMessage.setText(">>" + theReply.getBbsId());
+ }else{
+ txtMessage.setText(">>" + theReply.getId());
+ }
+ }else if (theReply != null){
+ txtFilePath.setVisibility(theReply.getParentBoard().isCanAttachFiles() ? View.VISIBLE : View.GONE);
+ btnSelectFile.setVisibility(theReply.getParentBoard().isCanAttachFiles() ? View.VISIBLE : View.GONE);
+ }
+
+ LinearLayout layoutProcess = (LinearLayout)findViewById(R.id.layoutPostProcess);
+ layoutProcess.setVisibility(View.GONE);
+ filePath = (EditText) findViewById(R.id.txtFilePath);
+
+ Button bBold = (Button) findViewById(R.id.buttonBold);
+ Button bStrike = (Button) findViewById(R.id.buttonStrike);
+ Button bList = (Button) findViewById(R.id.buttonList);
+ Button bCode = (Button) findViewById(R.id.buttonCode);
+ Button bUnder = (Button) findViewById(R.id.buttonUnderline);
+ Button bItalic = (Button) findViewById(R.id.buttonItalic);
+ Button select = (Button) findViewById(R.id.btnSelectFiles);
+
+ bBold.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ applyTag("b");
+ }
+ });
+ bItalic.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ applyTag("i");
+ }
+ });
+ bStrike.setOnClickListener(new View.OnClickListener(){
+ @Override
+ public void onClick(View v) {
+ applyTag("strike");
+ }
+ });
+ bList.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ applyTag("ul");
+ }
+ });
+ bCode.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ applyTag("code");
+ }
+ });
+ bUnder.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ applyTag("u");
+ }
+ });
+
+ select.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ startActivityForResult(Intent.createChooser(intent, "Seleccionar Archivo"), PICK_IMAGE);
+ }
+ });
+
+ }
+
+ private void applyTag(String tag){
+ TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
+ if (txtMessage.getSelectionStart() == -1){
+ txtMessage.setText(txtMessage.getText() + "<" + tag + ">" + tag +">");
+ }else{
+ String s = txtMessage.getText().toString();
+ String a = s.substring(0, txtMessage.getSelectionStart());
+ String b = s.substring(txtMessage.getSelectionStart(), txtMessage.getSelectionEnd());
+ String c = s.substring(txtMessage.getSelectionEnd(), txtMessage.getText().length());
+ txtMessage.setText(a + "<" + tag + ">" + b + "" + tag + ">" + c);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_replyform, menu);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.action_form_reply){
+ TextView txtName = (TextView) findViewById(R.id.txtPosterName);
+ TextView txtEmail = (TextView) findViewById(R.id.txtEmail);
+ TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
+ TextView txtThreadSubject = (TextView) findViewById(R.id.txtThreadSubject);
+ makePost(txtName.getText().toString(), txtEmail.getText().toString(), txtMessage.getText().toString(), txtThreadSubject.getText().toString());
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
+ Uri selectedImage = data.getData();
+ String picturePath = ContentProviderUtils.getPath(getApplicationContext(), selectedImage);
+ selectedFile = picturePath;
+ filePath.setText(picturePath);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ }
+
+ private void makePost(String name, String email, String message, String subject){
+ int parentId = theReply.realParentId();
+ // Si el parentId = 0 && subject != "" ==> Nuevo hilo
+ if (newthread){
+ parentId = 0;
+ }
+ LinearLayout layoutProcess = (LinearLayout)findViewById(R.id.layoutPostProcess);
+ layoutProcess.setVisibility(View.VISIBLE);
+ final RelativeLayout formSendPost = (RelativeLayout) findViewById(R.id.layoutForm);
+ formSendPost.setVisibility(View.GONE);
+ ProgressBar progess = (ProgressBar) findViewById(R.id.barPosting);
+ final TextView err = (TextView)findViewById(R.id.txtPostingState);
+ err.setText("");
+ File up = new File(selectedFile);
+
+ if (newthread){
+ if (selectedFile.isEmpty()){
+ Ion.with(getApplicationContext())
+ .load("http://bienvenidoainternet.org/cgi/post")
+ .setLogging("posting", Log.VERBOSE)
+ .uploadProgressBar(progess)
+ .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
+ .setMultipartParameter("password", password)
+ .setMultipartParameter("fielda", name)
+ .setMultipartParameter("fieldb", email)
+ .setMultipartParameter("name", "")
+ .setMultipartParameter("email", "")
+ .setMultipartParameter("message", message)
+ .setMultipartParameter("subject", subject)
+ .setMultipartParameter("noimage", "on")
+ .asString()
+ .setCallback(new FutureCallback() {
+ @Override
+ public void onCompleted(Exception e, String result) {
+ Log.v("sendPost", result);
+ if (e != null) {
+ Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
+ formSendPost.setVisibility(View.VISIBLE);
+ err.setText("Error: " + e.getMessage());
+ e.printStackTrace();
+ } else {
+ if (result.contains("ERROR : Flood detectado.")){
+ Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
+ }
+ finish();
+ }
+ }
+ });
+ }else{
+ Ion.with(getApplicationContext())
+ .load("http://bienvenidoainternet.org/cgi/post")
+ .uploadProgressBar(progess)
+ .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
+ .setMultipartParameter("password", password)
+ .setMultipartParameter("fielda", name)
+ .setMultipartParameter("fieldb", email)
+ .setMultipartParameter("name", "")
+ .setMultipartParameter("email", "")
+ .setMultipartParameter("message", message)
+ .setMultipartParameter("subject", subject)
+ .setMultipartFile("file", up)
+ .asString()
+ .setCallback(new FutureCallback() {
+ @Override
+ public void onCompleted(Exception e, String result) {
+ Log.v("sendPost", result);
+ if (e != null){
+ Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
+ formSendPost.setVisibility(View.VISIBLE);
+ err.setText("Error: " + e.getMessage());
+ e.printStackTrace();
+ }else{
+ if (result.contains("ERROR : Flood detectado.")){
+ Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
+ }
+ finish();
+ }
+ }
+ });
+ }
+ }else{
+ if (selectedFile.isEmpty()){
+ Ion.with(getApplicationContext())
+ .load("http://bienvenidoainternet.org/cgi/post")
+ .setLogging("posting", Log.VERBOSE)
+ .uploadProgressBar(progess)
+ .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
+ .setMultipartParameter("parent", String.valueOf(parentId))
+ .setMultipartParameter("password", password)
+ .setMultipartParameter("fielda", name)
+ .setMultipartParameter("fieldb", email)
+ .setMultipartParameter("name", "")
+ .setMultipartParameter("email", "")
+ .setMultipartParameter("message", message)
+ .setMultipartParameter("subject", subject)
+ .asString()
+ .setCallback(new FutureCallback() {
+ @Override
+ public void onCompleted(Exception e, String result) {
+ Log.v("sendPost", result);
+ if (e != null) {
+ Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
+ formSendPost.setVisibility(View.VISIBLE);
+ err.setText("Error: " + e.getMessage());
+ e.printStackTrace();
+ } else {
+ if (result.contains("ERROR : Flood detectado.")){
+ Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
+ }
+ finish();
+ }
+ }
+ });
+ }else{
+ Ion.with(getApplicationContext())
+ .load("http://bienvenidoainternet.org/cgi/post")
+ .uploadProgressBar(progess)
+ .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
+ .setMultipartParameter("parent", String.valueOf(parentId))
+ .setMultipartParameter("password", password)
+ .setMultipartParameter("fielda", name)
+ .setMultipartParameter("fieldb", email)
+ .setMultipartParameter("name", "")
+ .setMultipartParameter("email", "")
+ .setMultipartParameter("message", message)
+ .setMultipartParameter("subject", subject)
+ .setMultipartFile("file", up)
+ .asString()
+ .setCallback(new FutureCallback() {
+ @Override
+ public void onCompleted(Exception e, String result) {
+ Log.v("sendPost", result);
+ if (e != null){
+ Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
+ formSendPost.setVisibility(View.VISIBLE);
+ err.setText("Error: " + e.getMessage());
+ e.printStackTrace();
+ }else{
+ if (result.contains("ERROR : Flood detectado.")){
+ Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
+ }else{
+ Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
+ }
+ finish();
+ }
+ }
+ });
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/SettingsActivity.java b/app/src/main/java/org/bienvenidoainternet/app/SettingsActivity.java
new file mode 100644
index 0000000..021aed5
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/SettingsActivity.java
@@ -0,0 +1,204 @@
+package org.bienvenidoainternet.app;
+
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
+import android.support.v7.app.ActionBar;
+import android.view.MenuItem;
+
+import java.util.List;
+
+/**
+ * A {@link PreferenceActivity} that presents a set of application settings. On
+ * handset devices, settings are presented as a single list. On tablets,
+ * settings are split by category, with category headers shown to the left of
+ * the list of settings.
+ *
+ * See
+ * Android Design: Settings for design guidelines and the Settings
+ * API Guide for more information on developing a Settings UI.
+ */
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class SettingsActivity extends AppCompatPreferenceActivity {
+ /**
+ * A preference value change listener that updates the preference's summary
+ * to reflect its new value.
+ */
+ private static boolean requireReset = false;
+ private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ String stringValue = value.toString();
+
+ if (preference instanceof ListPreference) {
+ // For list preferences, look up the correct display value in
+ // the preference's 'entries' list.
+ ListPreference listPreference = (ListPreference) preference;
+ int index = listPreference.findIndexOfValue(stringValue);
+
+ // Set the summary to reflect the new value.
+ preference.setSummary(
+ index >= 0
+ ? listPreference.getEntries()[index]
+ : null);
+
+ }else {
+ // For all other preferences, set the summary to the value's
+ // simple string representation.
+ preference.setSummary(stringValue);
+ }
+ System.out.println(preference.getKey());
+ return true;
+ }
+ };
+
+ /**
+ * Helper method to determine if the device has an extra-large screen. For
+ * example, 10" tablets are extra-large.
+ */
+ private static boolean isXLargeTablet(Context context) {
+ return (context.getResources().getConfiguration().screenLayout
+ & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
+ }
+
+ /**
+ * Binds a preference's summary to its value. More specifically, when the
+ * preference's value is changed, its summary (line of text below the
+ * preference title) is updated to reflect the value. The summary is also
+ * immediately updated upon calling this method. The exact display format is
+ * dependent on the type of preference.
+ *
+ * @see #sBindPreferenceSummaryToValueListener
+ */
+ private static void bindPreferenceSummaryToValue(Preference preference) {
+ // Set the listener to watch for value changes.
+ preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
+ requireReset = true;
+ // Trigger the listener immediately with the preference's
+ // current value.
+ sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
+ PreferenceManager
+ .getDefaultSharedPreferences(preference.getContext())
+ .getString(preference.getKey(), ""));
+ }
+
+ @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();
+ }
+
+ /**
+ * Set up the {@link android.app.ActionBar}, if the API is available.
+ */
+ private void setupActionBar() {
+ ActionBar actionBar = getSupportActionBar();
+
+ if (actionBar != null) {
+ // Show the Up button in the action bar.
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onIsMultiPane() {
+ return isXLargeTablet(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public void onBuildHeaders(List target) {
+// loadHeadersFromResource(R.xml.pref_headers, target);
+ }
+
+ /**
+ * This method stops fragment injection in malicious applications.
+ * Make sure to deny any unknown fragments here.
+ */
+ protected boolean isValidFragment(String fragmentName) {
+ return PreferenceFragment.class.getName().equals(fragmentName)
+ || GeneralPreferenceFragment.class.getName().equals(fragmentName)
+ ;
+ }
+
+ @Override
+ public void onBackPressed() {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra("result", requireReset);
+ setResult(Activity.RESULT_OK,returnIntent);
+ finish();
+ super.onBackPressed();
+ }
+
+ /**
+ * This fragment shows general preferences only. It is used when the
+ * activity is showing a two-pane settings UI.
+ */
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public class GeneralPreferenceFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ setHasOptionsMenu(true);
+
+ // Bind the summaries of EditText/List/Dialog/Ringtone preferences
+ // to their values. When their values change, their summaries are
+ // updated to reflect the new value, per the Android Design
+ // guidelines.
+// bindPreferenceSummaryToValue(findPreference("example_text"));
+ bindPreferenceSummaryToValue(findPreference("pref_theme"));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+ if (id == android.R.id.home) {
+// startActivity(new Intent(getActivity(), SettingsActivity.class));
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra("result",requireReset);
+ setResult(Activity.RESULT_OK,returnIntent);
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/ThemeManager.java b/app/src/main/java/org/bienvenidoainternet/app/ThemeManager.java
new file mode 100644
index 0000000..04ed3fd
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/ThemeManager.java
@@ -0,0 +1,140 @@
+package org.bienvenidoainternet.app;
+
+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;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class ThemeManager {
+ private int currentThemeId;
+ 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 = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.sageColor});
+ return a.getColor(0, Color.CYAN);
+ }
+
+ public int getMarginColor(){
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.marginColor});
+ return a.getColor(0, Color.CYAN);
+ }
+
+ public void updateThemeId(int id){
+ this.currentThemeId = id;
+ }
+
+ public int getNameColor() {
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.nameColor});
+ return a.getColor(0, Color.CYAN);
+ }
+
+ public int getTripcodeColor() {
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.tripcodeColor});
+ return a.getColor(0, Color.CYAN);
+ }
+
+ public int getPrimaryColor(){
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimary});
+ return a.getColor(0, Color.CYAN);
+ }
+ public int getPrimaryDarkColor(){
+ TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimaryDark});
+ return a.getColor(0, Color.CYAN);
+ }
+
+ public boolean 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/app/ThreadListAdapter.java b/app/src/main/java/org/bienvenidoainternet/app/ThreadListAdapter.java
new file mode 100644
index 0000000..b3870eb
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/ThreadListAdapter.java
@@ -0,0 +1,337 @@
+package org.bienvenidoainternet.app;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.graphics.drawable.ColorDrawable;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.text.Html;
+import android.text.Layout;
+import android.text.Spannable;
+import android.text.style.ClickableSpan;
+import android.text.style.URLSpan;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import org.bienvenidoainternet.app.structure.BoardItem;
+import org.bienvenidoainternet.app.structure.BoardItemFile;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class ThreadListAdapter extends ArrayAdapter{
+ private Context context;
+ private ThemeManager tm;
+ Typeface monaFont;
+ public boolean listThreads = false;
+ private ArrayList boardItems = new ArrayList();
+ private static final String EXTRA_FILELIST = "fileList";
+
+ public ThreadListAdapter(Context context, List objects, ThemeManager tm) {
+ super(context, 0, objects);
+ this.context = context;
+ this.tm = tm;
+ monaFont = Typeface.createFromAsset(context.getAssets(), "fonts/mona.ttf");
+ }
+
+ public void updateBoardItems(ArrayList boardItems){
+ this.boardItems = boardItems;
+ }
+
+ private String intToHexString(int i){
+ return String.format("#%06X", (0xFFFFFF & i));
+ }
+ public static Map computeDiff(Date date1, Date date2) {
+ long diffInMillies = date2.getTime() - date1.getTime();
+ List units = new ArrayList(EnumSet.allOf(TimeUnit.class));
+ Collections.reverse(units);
+ Map result = new LinkedHashMap();
+ long milliesRest = diffInMillies;
+ for ( TimeUnit unit : units ) {
+ long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
+ long diffInMilliesForUnit = unit.toMillis(diff);
+ milliesRest = milliesRest - diffInMilliesForUnit;
+ result.put(unit,diff);
+ }
+ return result;
+ }
+ @Override
+ public View getView(final int position, final View convertView, final ViewGroup parent){
+ LayoutInflater inflater = (LayoutInflater)getContext()
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ View listItemView = convertView;
+ if (null == convertView) {
+ listItemView = inflater.inflate(
+ R.layout.thread_item,
+ parent,
+ false);
+ }
+
+ final BoardItem boardItem = getItem(position);
+ if (boardItem == null){
+ return listItemView;
+ }
+ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getContext());
+ boolean useMonaFont = settings.getBoolean("setting_monafont", true);
+ boolean monaBbsOnly = settings.getBoolean("setting_mona_bbsonly", true);
+ boolean resizeThumb = settings.getBoolean("setting_resize_thumbs", true);
+ int marginColor = tm.getMarginColor();
+ int sageColor = tm.getSageColor();
+ int nameColor = tm.getNameColor();
+ int tripcodeColor = tm.getTripcodeColor();
+ String hexColor =intToHexString(boardItem.getIdColor());
+ String sageHexColor = intToHexString(sageColor);
+ String nameHexColor = intToHexString(nameColor);
+ String tripcodeHexColor = intToHexString(tripcodeColor);
+ String strId = "";
+
+ TextView txtTitle = (TextView)listItemView.findViewById(R.id.lv_txtTitle);
+ TextView txtPoster = (TextView)listItemView.findViewById(R.id.lv_txtPoster);
+ TextView txtBody = (TextView) listItemView.findViewById(R.id.lv_txtBody);
+ TextView txtReplies = (TextView) listItemView.findViewById(R.id.lv_txtReplyCounter);
+ TextView txtFileInfo = (TextView) listItemView.findViewById(R.id.lv_txtFileInfo);
+ ImageView ivMargin = (ImageView)listItemView.findViewById(R.id.ivMargin);
+ ImageView ivThumb = (ImageView)listItemView.findViewById(R.id.ivThumb);
+
+// Log.v("resize", resizeThumb + "");
+ if (resizeThumb){
+ ivThumb.setScaleType(ImageView.ScaleType.FIT_XY);
+ }else{
+ ivThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
+ }
+
+ ivThumb.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!boardItem.getThumb().isEmpty() && convertView != null){
+ if (boardItem.getFile().endsWith(".webm") || boardItem.getFile().endsWith(".ogg") || boardItem.getFile().endsWith(".opus") || boardItem.getFile().endsWith(".swf") || boardItem.youtubeLink){
+ Intent in;
+ if (boardItem.youtubeLink){
+ in = new Intent(Intent.ACTION_VIEW, Uri.parse(boardItem.youtubeURL));
+ }else{
+ in = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bienvenidoainternet.org/" + boardItem.getParentBoard().getBoardDir() + "/src/" + boardItem.getFile()));
+ }
+ in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ v.getContext().startActivity(in);
+ }else {
+ Intent in = new Intent(convertView.getContext(), ViewerActivity.class);
+ Bundle b = new Bundle();
+ ArrayList fileList = new ArrayList();
+ int relativePosition = 0;
+ for (int i = 0; i < boardItems.size(); i++){
+ if (!boardItems.get(i).getFile().isEmpty()){
+ if (boardItems.get(i).getFile().equals(boardItem.getFile())){
+ relativePosition = fileList.size();
+ }
+ fileList.add(new BoardItemFile("http://bienvenidoainternet.org/" + boardItems.get(i).getParentBoard().getBoardDir() + "/src/" + boardItems.get(i).getFile(), boardItems.get(i).getFile(), boardItems.get(i).getParentBoard().getBoardDir()));
+ }
+ }
+ b.putParcelableArrayList(EXTRA_FILELIST, fileList);
+ b.putInt("position", relativePosition);
+ in.putExtras(b);
+ convertView.getContext().startActivity(in);
+ }
+ }
+ }
+ });
+
+
+ ivMargin.setImageDrawable(new ColorDrawable(marginColor));
+
+ if (useMonaFont){
+ if (monaBbsOnly && boardItem.getParentBoard() != null){
+ if (boardItem.getParentBoard().getBoardType() == 1){
+ txtBody.setTypeface(monaFont);
+ }
+ }else{
+ txtBody.setTypeface(monaFont);
+ }
+ }
+
+ // Si es una respuesta ocultamos el margen
+ if (boardItem.isReply){
+ ivMargin.setVisibility(View.VISIBLE);
+ txtTitle.setVisibility(View.GONE);
+ }else{
+ txtTitle.setVisibility(View.VISIBLE);
+ ivMargin.setVisibility(View.GONE);
+ txtTitle.setText(boardItem.getSubject());
+ }
+
+ // Si el fragmento esta viendo un hilo ocultamos los margenes
+ if (listThreads){
+ ivMargin.setVisibility(View.GONE);
+ }
+
+ // Si el item está eliminado activamos el soporte de
+ if (boardItem.getDeletedCode() != 0){
+ txtBody.setPaintFlags(txtBody.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
+ }else{
+ txtBody.setPaintFlags(txtBody.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
+ }
+
+
+ if (boardItem.getThumb().isEmpty()){
+ ivThumb.setVisibility(View.GONE);
+ }else{
+ if (boardItem.getThumbBitmap() != null){
+ ivThumb.setVisibility(View.VISIBLE);
+ ivThumb.setImageBitmap(boardItem.getThumbBitmap());
+ }else{
+ ivThumb.setVisibility(View.VISIBLE);
+ ivThumb.setImageResource(R.drawable.blank);
+ }
+ }
+
+ Map timeDiff = computeDiff(new Date(boardItem.getTimeStamp() * 1000L), new Date(System.currentTimeMillis()));
+ String strTimeDiff = "";
+ if (timeDiff.get(TimeUnit.SECONDS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.SECONDS) + (timeDiff.get(TimeUnit.SECONDS) == 1 ? " segundo" : " segundos");
+ }
+ if (timeDiff.get(TimeUnit.MINUTES) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.MINUTES) + (timeDiff.get(TimeUnit.MINUTES) == 1 ? " minuto" : " minutos");
+ }
+ if (timeDiff.get(TimeUnit.HOURS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.HOURS) + (timeDiff.get(TimeUnit.HOURS) == 1 ? " hora" : " horas");
+ }
+ if (timeDiff.get(TimeUnit.DAYS) != 0){
+ strTimeDiff = "Hace " + timeDiff.get(TimeUnit.DAYS) + (timeDiff.get(TimeUnit.DAYS) == 1 ? " día" : " días");
+ }
+
+
+ if (!boardItem.getPosterId().isEmpty() && !boardItem.getPosterId().equals("???")){
+ strId = "[" + boardItem.getPosterId() + "] ";
+ }
+
+ // Si estamos mostrando un item de BBS, mostrar el ID_BBS en ves del ID del post
+ int idToDisplay = 0;
+ if (boardItem.getParentBoard() != null){
+ if (boardItem.getParentBoard().getBoardType() == 1){
+ idToDisplay = boardItem.getBbsId();
+ }else{
+ idToDisplay = boardItem.getId();
+ }
+ }else{
+ idToDisplay = boardItem.getId();
+ }
+
+ txtPoster.setText(Html.fromHtml("No. " + idToDisplay + " por " + boardItem.getName() + " "
+ + (boardItem.getTripcode() == "" ? "" : "" + boardItem.getTripcode() + "") + strId + " " + strTimeDiff));
+ txtBody.setText(Html.fromHtml(boardItem.getMessage()));
+
+ txtReplies.setVisibility(boardItem.isReply ? View.GONE : View.VISIBLE);
+ txtReplies.setText(boardItem.getTotalReplies() + " respuestas " + (boardItem.getTotalFiles() == 0 ? "" : ", " + boardItem.getTotalFiles() + " archivos"));
+
+ String fileExt = "";
+ txtFileInfo.setVisibility(boardItem.getThumb().isEmpty() ? View.GONE : View.VISIBLE);
+
+ if (!boardItem.getThumb().isEmpty() && boardItem.getThumb().startsWith("http")){
+ txtFileInfo.setText("YOUTUBE");
+ }else{
+ if (!boardItem.getFile().isEmpty()){
+ String[] pathSplit = boardItem.getFile().split("\\.");
+ if (pathSplit.length != 0){
+ fileExt = pathSplit[1].toUpperCase();
+ }
+ }
+ txtFileInfo.setText(fileExt + " " + (boardItem.getFileSize() / 1024) + " KB " + boardItem.getThumbHeight() + "x" + boardItem.getThumbWidth());
+ }
+
+
+ // Trasnparentar items con sage
+ if (convertView != null){
+ if (settings.getBoolean("pref_transparent_sage", true)){
+ convertView.setAlpha(boardItem.isSage() ? 0.75F : 1.0F);
+ }
+ }
+
+ /*
+ http://stackoverflow.com/questions/8558732/listview-textview-with-linkmovementmethod-makes-list-item-unclickable
+ */
+ txtBody.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ boolean ret = false;
+ CharSequence text = ((TextView) v).getText();
+ Spannable stext = Spannable.Factory.getInstance().newSpannable(text);
+ TextView widget = (TextView) v;
+ int action = event.getAction();
+
+ if (action == MotionEvent.ACTION_UP ||
+ action == MotionEvent.ACTION_DOWN) {
+ int x = (int) event.getX();
+ int y = (int) event.getY();
+
+ x -= widget.getTotalPaddingLeft();
+ y -= widget.getTotalPaddingTop();
+
+ x += widget.getScrollX();
+ y += widget.getScrollY();
+
+ Layout layout = widget.getLayout();
+ int line = layout.getLineForVertical(y);
+ int off = layout.getOffsetForHorizontal(line, x);
+
+ ClickableSpan[] link = stext.getSpans(off, off, ClickableSpan.class);
+/*04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: zonavip
+04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: read
+04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: 43872
+04-03 17:46:54.650 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: 25*/
+ if (link.length != 0) {
+ if (link[0] instanceof URLSpan){
+ URLSpan uspan = (URLSpan) link[0];
+ if (uspan.getURL().contains("/read/") && !uspan.getURL().contains("http")){
+ String url = uspan.getURL();
+ String[] parts = url.split("/");
+ if (parts.length == 4 && listThreads){
+ Log.v("ConvertView", convertView.getParent().toString());
+ }
+ return true;
+ }
+ }
+ if (action == MotionEvent.ACTION_UP) {
+ link[0].onClick(widget);
+ }
+ ret = true;
+ }
+ }
+ return ret;
+ }
+ });
+ return listItemView;
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/ViewerActivity.java b/app/src/main/java/org/bienvenidoainternet/app/ViewerActivity.java
new file mode 100644
index 0000000..917199e
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/ViewerActivity.java
@@ -0,0 +1,137 @@
+package org.bienvenidoainternet.app;
+
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.media.MediaScannerConnection;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Environment;
+import android.support.v4.view.ViewPager;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.ProgressBar;
+import android.widget.Toast;
+
+import org.bienvenidoainternet.app.structure.BoardItemFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import layout.FragmentImage;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class ViewerActivity extends AppCompatActivity implements FragmentImage.OnFragmentInteractionListener {
+ private static final String EXTRA_FILELIST = "fileList", EXTRA_RELATIVEPOSITION = "position";
+ private ViewPager imagePager;
+ public ProgressBar barDownload;
+ private int relativePosition = 0;
+
+ public ArrayList fileList = new ArrayList();
+ private CustomFragmentPagerAdapter pagerAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getIntent().getExtras() != null){
+ fileList = getIntent().getParcelableArrayListExtra(EXTRA_FILELIST);
+ relativePosition = getIntent().getIntExtra(EXTRA_RELATIVEPOSITION, 0);
+ }
+ setContentView(R.layout.activity_viewer);
+ barDownload = (ProgressBar) findViewById(R.id.downloadProgressBar);
+ imagePager = (ViewPager) findViewById(R.id.imagePager);
+ this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
+ for (int i = 0; i < fileList.size(); i++){
+ Log.v("ImageViewer", fileList.get(i).toString());
+ pagerAdapter.addFragment(FragmentImage.newInstance(fileList.get(i)));
+ }
+ imagePager.setAdapter(pagerAdapter);
+ imagePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ getSupportActionBar().setSubtitle("(" + (position + 1) + " / " + fileList.size() + ") " + fileList.get(position).file);
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+
+ }
+ });
+ imagePager.setCurrentItem(relativePosition);
+ this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ File baiDir = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/");
+ if (!baiDir.exists()){
+ baiDir.mkdir();
+ }
+ if (item.getItemId() == R.id.menu_save_img){
+ BoardItemFile boardItemFile = fileList.get(imagePager.getCurrentItem());
+ File to = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + boardItemFile.file);
+ ContextWrapper cw = new ContextWrapper(getApplicationContext());
+ File directory = cw.getDir("src", Context.MODE_PRIVATE);
+ File fileSource = new File(directory, boardItemFile.boardDir + "_" + boardItemFile.file);
+ try{
+ InputStream in = new FileInputStream(fileSource);
+ OutputStream out = new FileOutputStream(to);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ Toast.makeText(getApplicationContext(), boardItemFile.file + " guardado.", Toast.LENGTH_LONG).show();
+ MediaScannerConnection.scanFile(this, new String[]{to.getPath()}, new String[]{"image/jpeg"}, null);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+
+ }
+ if (item.getItemId() == android.R.id.home) {
+ onBackPressed();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_viewer, menu);
+ return true;
+ }
+
+ @Override
+ public void onFragmentInteraction(Uri uri) {
+
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/structure/Board.java b/app/src/main/java/org/bienvenidoainternet/app/structure/Board.java
new file mode 100644
index 0000000..bcd9b61
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/structure/Board.java
@@ -0,0 +1,87 @@
+package org.bienvenidoainternet.app.structure;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+public class Board implements Parcelable{
+ private String boardName, boardDir;
+ private int boardType;
+
+ public boolean isCanAttachFiles() {
+ return canAttachFiles;
+ }
+
+ public void setCanAttachFiles(boolean canAttachFiles) {
+ this.canAttachFiles = canAttachFiles;
+ }
+
+ private boolean canAttachFiles;
+ public Board(String boardName, String boardDir, int boardType, boolean canAttachFiles){
+ this.boardName = boardName;
+ this.boardDir = boardDir;
+ this.boardType = boardType;
+ this.canAttachFiles = canAttachFiles;
+ }
+
+ public Board(Parcel in){
+ this.boardName = in.readString();
+ this.boardDir = in.readString();
+ this.boardType = in.readInt();
+ this.canAttachFiles = in.readByte() != 0;
+ }
+
+ public String getBoardDir() {
+ return boardDir;
+ }
+
+ public String getBoardName() {
+ return boardName;
+ }
+
+ public int getBoardType() {
+ return boardType;
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public Board createFromParcel(Parcel in) {
+ return new Board(in);
+ }
+
+ @Override
+ public Board[] newArray(int size) {
+ return new Board[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(boardName);
+ dest.writeString(boardDir);
+ dest.writeInt(boardType);
+ dest.writeByte((byte)(canAttachFiles ? 1 : 0));
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItem.java b/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItem.java
new file mode 100644
index 0000000..9b81e8b
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItem.java
@@ -0,0 +1,352 @@
+package org.bienvenidoainternet.app.structure;
+
+import android.graphics.Bitmap;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+public class BoardItem implements Parcelable {
+ private String name = "";
+ private String timestamp_formatted = "";
+ private String thumb = "";
+ private String tripcode = "";
+ private String email = "";
+ private String file = "";
+ private String message = "";
+ private String subject = "";
+ private String posterId = "";
+ public String youtubeURL = "", youtubeID = "";
+ private int parentid = 0, id = 0, idcolor, totalreplies = 0, totalfiles, thumb_height, thumb_weight, filesize, deleted_code, bbs_id = 1, parentPostCount;
+ private long timestamp = 0;
+
+ private Bitmap thumbBitmap = null;
+ public boolean downloadingThumb = false;
+ public boolean isReply = false, isLocked = false, youtubeLink = false;
+ private Board parentBoard = null;
+
+ protected BoardItem(Parcel in) {
+ name = in.readString();
+ timestamp_formatted = in.readString();
+ thumb = in.readString();
+ tripcode = in.readString();
+ email = in.readString();
+ file = in.readString();
+ message = in.readString();
+ subject = in.readString();
+ posterId = in.readString();
+ youtubeURL = in.readString();
+ youtubeID = in.readString();
+ parentid = in.readInt();
+ id = in.readInt();
+ idcolor = in.readInt();
+ totalreplies = in.readInt();
+ totalfiles = in.readInt();
+ thumb_height = in.readInt();
+ thumb_weight = in.readInt();
+ filesize = in.readInt();
+ deleted_code = in.readInt();
+ bbs_id = in.readInt();
+ parentPostCount = in.readInt();
+ timestamp = in.readLong();
+ thumbBitmap = in.readParcelable(Bitmap.class.getClassLoader());
+ downloadingThumb = in.readByte() != 0;
+ isReply = in.readByte() != 0;
+ isLocked = in.readByte() != 0;
+ youtubeLink = in.readByte() != 0;
+ parentBoard = in.readParcelable(Board.class.getClassLoader());
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public BoardItem createFromParcel(Parcel in) {
+ return new BoardItem(in);
+ }
+
+ @Override
+ public BoardItem[] newArray(int size) {
+ return new BoardItem[size];
+ }
+ };
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ public int getFileSize() {
+ return filesize;
+ }
+
+ public void setFilesize(int filesize) {
+ this.filesize = filesize;
+ }
+
+ public int getIdColor() {
+ return idcolor;
+ }
+
+ public void setIdColor(int idcolor) {
+ this.idcolor = idcolor;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ Document msg = Jsoup.parse(message);
+ if (!msg.getElementsByClass("yt").isEmpty()){
+ Element you = msg.getElementsByClass("yt").first();
+ if (this.getFile().isEmpty()){
+ this.thumb = you.getElementsByTag("img").attr("src");
+ String[] parts = thumb.split("/");
+ this.youtubeLink = true;
+ this.youtubeURL = "https://www.youtube.com/watch?v=" + parts[4];
+ this.youtubeID = parts[4];
+ Log.v("ID", youtubeID);
+ }
+ }
+ msg.select("img[src]").remove();
+ msg.select("span[class=unkfunc]").tagName("font").attr("color", "#8fb56c").wrap("");
+ msg.select("div[class=yt]").wrap("");
+ this.message = msg.html();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Board getParentBoard() {
+ return parentBoard;
+ }
+
+ public void setParentBoard(Board parentBoard) {
+ this.parentBoard = parentBoard;
+ }
+
+ public int getParentId() {
+ return parentid;
+ }
+
+ public void setParentId(int parentid) {
+ this.parentid = parentid;
+ }
+
+ public int getParentPostCount() {
+ return parentPostCount;
+ }
+
+ public void setParentPostCount(int parentPostCount) {
+ this.parentPostCount = parentPostCount;
+ }
+
+ public String getPosterId() {
+ return posterId;
+ }
+
+ public void setPosterId(String posterId) {
+ this.posterId = posterId;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ public String getThumb() {
+ return thumb;
+ }
+
+ public void setThumb(String thumb) {
+ this.thumb = thumb;
+ }
+
+ public int getThumbHeight() {
+ return thumb_height;
+ }
+
+ public void setThumbHeight(int thumb_height) {
+ this.thumb_height = thumb_height;
+ }
+
+ public int getThumbWidth() {
+ return thumb_weight;
+ }
+
+ public void setThumbWidth(int thumb_weight) {
+ this.thumb_weight = thumb_weight;
+ }
+
+ public Bitmap getThumbBitmap() {
+ return thumbBitmap;
+ }
+
+ public void setThumbBitmap(Bitmap thumbBitmap) {
+ this.thumbBitmap = thumbBitmap;
+ }
+
+ public long getTimeStamp() {
+ return timestamp;
+ }
+
+ public void setTimeStamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String getTimeStampFormatted() {
+ return timestamp_formatted;
+ }
+
+ public void setTimeStampFormatted(String timestamp_formatted) {
+ this.timestamp_formatted = timestamp_formatted;
+ }
+
+ public int getTotalFiles() {
+ return totalfiles;
+ }
+
+ public void setTotalFiles(int totalfiles) {
+ this.totalfiles = totalfiles;
+ }
+
+ public int getTotalReplies() {
+ return totalreplies;
+ }
+
+ public void setTotalReplies(int totalreplies) {
+ this.totalreplies = totalreplies;
+ }
+
+ public String getTripcode() {
+ return tripcode;
+ }
+
+ public void setTripcode(String tripcode) {
+ this.tripcode = tripcode;
+ }
+
+ public int getDeletedCode() {
+ return deleted_code;
+ }
+
+ public void setDeletedCode(int deleted_code) {
+ this.deleted_code = deleted_code;
+ if (deleted_code == 1){
+ this.message = "Eliminado por el usuario.";
+ }else if (deleted_code == 2){
+ this.message = "Eliminado por el Staff.";
+ }
+ }
+
+ public int getBbsId() {
+ return bbs_id;
+ }
+
+ public void setBbsId(int bbs_id) {
+ this.bbs_id = bbs_id;
+ }
+
+ public int realParentId(){
+ if (parentid == 0){
+ return id;
+ }
+ return parentid;
+ }
+
+ public BoardItem() {
+
+ }
+
+ public boolean isSage(){
+ return this.email.equals("sage");
+ }
+
+ public void setLockStatus(int i){
+ this.isLocked = i == 0 ? false : true;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(name);
+ dest.writeString(timestamp_formatted);
+ dest.writeString(thumb);
+ dest.writeString(tripcode);
+ dest.writeString(email);
+ dest.writeString(file);
+ dest.writeString(message);
+ dest.writeString(subject);
+ dest.writeString(posterId);
+ dest.writeString(youtubeURL);
+ dest.writeString(youtubeID);
+ dest.writeInt(parentid);
+ dest.writeInt(id);
+ dest.writeInt(idcolor);
+ dest.writeInt(totalreplies);
+ dest.writeInt(totalfiles);
+ dest.writeInt(thumb_height);
+ dest.writeInt(thumb_weight);
+ dest.writeInt(filesize);
+ dest.writeInt(deleted_code);
+ dest.writeInt(bbs_id);
+ dest.writeInt(parentPostCount);
+ dest.writeLong(timestamp);
+ dest.writeParcelable(thumbBitmap, flags);
+ dest.writeByte((byte) (downloadingThumb ? 1 : 0));
+ dest.writeByte((byte) (isReply ? 1 : 0));
+ dest.writeByte((byte) (isLocked ? 1 : 0));
+ dest.writeByte((byte) (youtubeLink ? 1 : 0));
+ dest.writeParcelable(parentBoard, flags);
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItemFile.java b/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItemFile.java
new file mode 100644
index 0000000..c215787
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/structure/BoardItemFile.java
@@ -0,0 +1,63 @@
+package org.bienvenidoainternet.app.structure;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+public class BoardItemFile implements Parcelable{
+ public String file;
+ public String fileURL;
+ public String boardDir;
+
+ public BoardItemFile(String fileURL, String file, String boardDir){
+ this.fileURL = fileURL;
+ this.file = file;
+ this.boardDir = boardDir;
+ }
+
+ protected BoardItemFile(Parcel in) {
+ file = in.readString();
+ fileURL = in.readString();
+ boardDir = in.readString();
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public BoardItemFile createFromParcel(Parcel in) {
+ return new BoardItemFile(in);
+ }
+
+ @Override
+ public BoardItemFile[] newArray(int size) {
+ return new BoardItemFile[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(file);
+ dest.writeString(fileURL);
+ dest.writeString(boardDir);
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/app/structure/ReplyID.java b/app/src/main/java/org/bienvenidoainternet/app/structure/ReplyID.java
new file mode 100644
index 0000000..dbb3d17
--- /dev/null
+++ b/app/src/main/java/org/bienvenidoainternet/app/structure/ReplyID.java
@@ -0,0 +1,68 @@
+package org.bienvenidoainternet.app.structure;
+
+import android.graphics.Color;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.bienvenidoainternet.app.ThemeManager;
+
+import java.util.Random;
+
+/**
+ * BaiApp - Bienvenido a internet Android Application
+ * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+public class ReplyID implements Parcelable{
+ public String id;
+ public int color;
+ public ReplyID(String id, ThemeManager tm){
+ this.id = id;
+ Random r = new Random();
+ if (tm.isDarkTheme()){
+ this.color = Color.rgb(r.nextInt(125) + 127, r.nextInt(127) + 127, r.nextInt(127) + 127);
+ }else{
+ this.color = Color.rgb(r.nextInt(125), r.nextInt(127), r.nextInt(127));
+ }
+ }
+
+ protected ReplyID(Parcel in) {
+ id = in.readString();
+ color = in.readInt();
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ @Override
+ public ReplyID createFromParcel(Parcel in) {
+ return new ReplyID(in);
+ }
+
+ @Override
+ public ReplyID[] newArray(int size) {
+ return new ReplyID[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(id);
+ dest.writeInt(color);
+ }
+}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/AppCompatPreferenceActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/AppCompatPreferenceActivity.java
deleted file mode 100644
index e89a927..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/AppCompatPreferenceActivity.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.support.annotation.LayoutRes;
-import android.support.annotation.Nullable;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatDelegate;
-import android.support.v7.widget.Toolbar;
-import android.view.MenuInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-/**
- * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
- * to be used with AppCompat.
- */
-public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
-
- private AppCompatDelegate mDelegate;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- getDelegate().installViewFactory();
- getDelegate().onCreate(savedInstanceState);
- super.onCreate(savedInstanceState);
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- getDelegate().onPostCreate(savedInstanceState);
- }
-
- public ActionBar getSupportActionBar() {
- return getDelegate().getSupportActionBar();
- }
-
- public void setSupportActionBar(@Nullable Toolbar toolbar) {
- getDelegate().setSupportActionBar(toolbar);
- }
-
- @Override
- public MenuInflater getMenuInflater() {
- return getDelegate().getMenuInflater();
- }
-
- @Override
- public void setContentView(@LayoutRes int layoutResID) {
- getDelegate().setContentView(layoutResID);
- }
-
- @Override
- public void setContentView(View view) {
- getDelegate().setContentView(view);
- }
-
- @Override
- public void setContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().setContentView(view, params);
- }
-
- @Override
- public void addContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().addContentView(view, params);
- }
-
- @Override
- protected void onPostResume() {
- super.onPostResume();
- getDelegate().onPostResume();
- }
-
- @Override
- protected void onTitleChanged(CharSequence title, int color) {
- super.onTitleChanged(title, color);
- getDelegate().setTitle(title);
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- getDelegate().onConfigurationChanged(newConfig);
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- getDelegate().onStop();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- getDelegate().onDestroy();
- }
-
- public void invalidateOptionsMenu() {
- getDelegate().invalidateOptionsMenu();
- }
-
- private AppCompatDelegate getDelegate() {
- if (mDelegate == null) {
- mDelegate = AppCompatDelegate.create(this, null);
- }
- return mDelegate;
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/CustomFragmentPagerAdapter.java b/app/src/main/java/org/bienvenidoainternet/baiparser/CustomFragmentPagerAdapter.java
deleted file mode 100644
index 1dd07c7..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/CustomFragmentPagerAdapter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentPagerAdapter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class CustomFragmentPagerAdapter extends FragmentPagerAdapter {
-
- // List of fragments which are going to set in the view pager widget
- List fragments;
-
- /**
- * Constructor
- *
- * @param fm
- * interface for interacting with Fragment objects inside of an
- * Activity
- */
- public CustomFragmentPagerAdapter(FragmentManager fm) {
- super(fm);
- this.fragments = new ArrayList();
- }
-
- /**
- * Add a new fragment in the list.
- *
- * @param fragment
- * a new fragment
- */
- public void addFragment(Fragment fragment) {
- this.fragments.add(fragment);
- }
-
- @Override
- public Fragment getItem(int arg0) {
- return this.fragments.get(arg0);
- }
-
- @Override
- public int getCount() {
- return this.fragments.size();
- }
-
-
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
deleted file mode 100644
index ebbe874..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/LicensesActivity.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.webkit.WebView;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-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
deleted file mode 100644
index 9a6a344..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java
+++ /dev/null
@@ -1,489 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.design.widget.FloatingActionButton;
-import android.support.design.widget.NavigationView;
-import android.support.v4.view.GravityCompat;
-import android.support.v4.view.ViewPager;
-import android.support.v4.widget.DrawerLayout;
-import android.support.v7.app.ActionBarDrawerToggle;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.SubMenu;
-import android.view.View;
-import android.widget.BaseAdapter;
-import android.widget.HeaderViewListAdapter;
-import android.widget.ListView;
-import android.widget.Toast;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import com.koushikdutta.async.future.FutureCallback;
-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;
-
-import java.util.ArrayList;
-import java.util.Random;
-
-import layout.FragmentBoardItemList;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class MainActivity extends AppCompatActivity
- implements NavigationView.OnNavigationItemSelectedListener, FragmentBoardItemList.OnFragmentInteractionListener {
- private ViewPager pager; // variable del ViewPager
- CustomFragmentPagerAdapter pagerAdapter; // Adaptador del ViewPager
- NavigationView navigationView;
- DrawerLayout drawer;
- FloatingActionButton fab;
- public ThemeManager themeManager;
- FragmentBoardItemList childFragment; // Segunda página del ViewPager, se muestra un solo hilo (selecionado del catálogo)
- FragmentBoardItemList mainFragment; // Primera página del ViewPager, se muestra una lista de hilos. (catálogo)
- Toolbar toolbar = null;
- public int currentThemeId = 0, themeId = 0; // Id del recurso, Id del tema
- public ArrayList boardList = new ArrayList<>();
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putInt("currentThemeId", currentThemeId);
- outState.putInt("themeId", themeId);
- outState.putParcelableArrayList("boardList", boardList);
- if (getSupportFragmentManager().getFragments() != null) {
- if (getSupportFragmentManager().getFragments().size() != 0) {
- try {
- getSupportFragmentManager().putFragment(outState, "mainFragment", mainFragment);
- getSupportFragmentManager().putFragment(outState, "childFragment", childFragment);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
- }
-
- public int getCurrentThemeId() {
- return currentThemeId;
- }
-
- @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);
- if (settings.getString("pref_password", "").isEmpty()){
- SharedPreferences.Editor edit = settings.edit();
- edit.putString("pref_password", makePassword());
- edit.commit();
- }
-
- 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
- public void onClick(View view) {
- if (pager.getCurrentItem() == 0){
- if (!mainFragment.getMode() && mainFragment.currentBoard != null){
- Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
- Bundle b = new Bundle();
- BoardItem temp = new BoardItem();
- temp.setParentBoard(mainFragment.currentBoard);
- b.putParcelable("theReply", temp);
- b.putBoolean("quoting", false);
- b.putBoolean("newthread", true);
- in.putExtras(b);
- startActivity(in);
- }
- }else{
- if (childFragment.currentBoard != null) {
- if (!childFragment.boardItems.isEmpty()) {
- try {
- Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
- Bundle b = new Bundle();
- BoardItem reply = childFragment.boardItems.get(0);
- if (!reply.isLocked) {
- b.putParcelable("theReply", reply);
- b.putBoolean("quoting", false);
- b.putBoolean("newthread", false);
- in.putExtras(b);
- startActivity(in);
- }else{
- Toast.makeText(getApplicationContext(), "Error: Este hilo está cerrado", Toast.LENGTH_LONG).show();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- });
- fab.setVisibility(View.GONE);
-
- drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
- drawer.setDrawerListener(toggle);
- toggle.syncState();
-
- navigationView = (NavigationView) findViewById(R.id.nav_view);
- navigationView.setNavigationItemSelectedListener(this);
-
- if (savedInstanceState != null) {
- mainFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState, "mainFragment");
- childFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState, "childFragment");
- } else {
- mainFragment = FragmentBoardItemList.newInstance(true, null, null);
- childFragment = FragmentBoardItemList.newInstance(false, null, null);
- }
-
- this.pager = (ViewPager) findViewById(R.id.pager);
- this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
- pagerAdapter.addFragment(mainFragment);
- pagerAdapter.addFragment(childFragment);
- this.pager.setAdapter(pagerAdapter);
-
- pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
- }
-
- @Override
- public void onPageSelected(int position) {
- if (position == 0){
- fab.setImageResource(R.drawable.ic_action_add);
- if (mainFragment.currentBoard != null) {
- toolbar.setTitle("Catálogo");
- toolbar.setSubtitle(mainFragment.currentBoard.getBoardName());
- }
- if (mainFragment.getMode()){
- toolbar.setTitle("Post recientes");
- toolbar.setSubtitle("");
- }
- if (mainFragment.getMode()){
- fab.hide();
- }else{
- fab.show();
- }
- }else if (position == 1){
- fab.setImageResource(R.drawable.ic_edit);
- if (childFragment.currentBoard != null) {
- toolbar.setTitle(childFragment.currentBoard.getBoardName());
- if (!childFragment.boardItems.isEmpty()){
- toolbar.setSubtitle(childFragment.boardItems.get(0).getSubject());
- }
- fab.show();
- }
- }
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
-
- }
- });
-
- if (boardList.isEmpty()){
- getBoardList();
- }else{
- Menu menu = navigationView.getMenu();
- SubMenu sub = menu.addSubMenu("Lista de Boards");
- for (Board b : boardList) {
- sub.add(b.getBoardName());
- }
- refreshNavigator();
- }
-
- if (tm.isDarkTheme()){
- navigationView.setBackgroundColor(0xFF888888);
- }
- }
-
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == 1) {
- if(resultCode == Activity.RESULT_OK){
- boolean result = data.getBooleanExtra("result", false);
- if (result){
- this.recreate();
- }
- }
- }
- }
-
- @Override
- public void onBackPressed() {
- if (this.pager.getCurrentItem() == 0) {
- super.onBackPressed();
- } else {
- this.pager.setCurrentItem(this.pager.getCurrentItem() - 1);
- return;
- }
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (drawer.isDrawerOpen(GravityCompat.START)) {
- drawer.closeDrawer(GravityCompat.START);
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- switch (id) {
- case R.id.action_exit:
- System.exit(0);
- break;
- case R.id.action_refresh:
- if (pager.getCurrentItem() == 0) {
- mainFragment.refresh();
- } else {
- childFragment.refresh();
- }
- if (boardList.isEmpty()){
- getBoardList();
- }
- break;
- case R.id.action_settings:
- Intent in2 = new Intent(getApplicationContext(), SettingsActivity.class);
- startActivityForResult(in2, 1);
- break;
- case R.id.action_to_bot:
- if (pager.getCurrentItem() == 0) {
- mainFragment.scrollToBotton();
- } else {
- childFragment.scrollToBotton();
- }
- break;
- case R.id.action_to_top:
- if (pager.getCurrentItem() == 0) {
- mainFragment.scrollToTop();
- } else {
- childFragment.scrollToTop();
- }
- break;
- case R.id.action_about:
- startActivity(new Intent(getApplicationContext(), LicensesActivity.class));
- break;
- }
- return super.onOptionsItemSelected(item);
- }
-
- @SuppressWarnings("StatementWithEmptyBody")
- @Override
- public boolean onNavigationItemSelected(MenuItem item) {
- // Handle navigation view item clicks here.
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- drawer.closeDrawer(GravityCompat.START);
- int id = item.getItemId();
- toolbar.setSubtitle(item.getTitle());
- if (id == R.id.nav_recent_post){
- toolbar.setTitle("Post recientes");
- toolbar.setSubtitle("");
- pager.setCurrentItem(0);
- mainFragment.loadRecentPost();
- }
- for (Board b : boardList){
- if (b.getBoardName() == item.getTitle()){
- System.out.println("Updating mainfragment to " + b.getBoardName() + " d: " + b.getBoardDir());
- mainFragment.setCatalogMode();
- mainFragment.updateBoardItems(b, null);
- pager.setCurrentItem(0);
- navigationView.getMenu().findItem(R.id.nav_recent_post).setChecked(false);
- }
- }
- return true;
- }
-
- public Board getBoardFromDir(String dir){
- for (Board b : boardList){
- if (b.getBoardDir().equals(dir)){
- return b;
- }
- }
- System.out.println("[MainActivity] Board not found " + dir);
- return null;
- }
-
-
- @Override
- public void onFragmentInteraction(Uri uri) {
-
- }
-
- @Override
- public void showThread(Board board, BoardItem thread) {
- childFragment.updateBoardItems(board, thread);
- pager.setCurrentItem(1);
- }
-
-
- @Override
- public void updateToolbar(Board cBoard, BoardItem btem) {
- if (pager.getCurrentItem() == 1){
- toolbar.setTitle(cBoard.getBoardName());
- toolbar.setSubtitle(btem.getSubject());
- }
- }
-
- @Override
- public void updateToolbar(String s) {
- toolbar.setTitle(s);
- toolbar.setSubtitle("");
- }
-
- @Override
- public void hideActionButton() {
- if (pager.getCurrentItem() == 1){
- fab.hide();
- }
- }
-
- @Override
- public void showActionButton() {
- if (pager.getCurrentItem() == 1){
- fab.show();
- }
- }
-
- @Override
- public void onThreadList() {
- if (pager.getCurrentItem() == 0){
- getSupportActionBar().setTitle("Catálogo");
- getSupportActionBar().setSubtitle(mainFragment.currentBoard.getBoardName());
- fab.show();
- }
- }
-
- @Override
- public void onThread() {
- if (pager.getCurrentItem() == 1){
- getSupportActionBar().setTitle(childFragment.currentBoard.getBoardName());
- getSupportActionBar().setSubtitle(childFragment.boardItems.get(0).getSubject());
- }
- }
-
- @Override
- public void onRecentPosts() {
- if (pager.getCurrentItem() == 0){
- getSupportActionBar().setTitle("Post recientes");
- getSupportActionBar().setSubtitle("");
- fab.hide();
- }
- }
-
- private void getBoardList(){
- Menu menu = navigationView.getMenu();
- final SubMenu sub = menu.addSubMenu("Lista de Boards");
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/cgi/api/boards")
- .asString()
- .setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, String result) {
- if (e != null) {
- e.printStackTrace();
- Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
- }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"), board.getInt("allow_image_replies") == 1 ? true : false);
- sub.add(parsedBoard.getBoardName());
- boardList.add(parsedBoard);
- }
- }catch (JSONException e1) {
- Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
- e1.printStackTrace();
- }
- }
- }
- });
-
- Board parsedBoard = new Board("Testing Field", "polka", 1, true);
- sub.add(parsedBoard.getBoardName());
- boardList.add(parsedBoard);
- refreshNavigator();
- }
-
- public void refreshNavigator(){
- for (int i = 0, count = navigationView.getChildCount(); i < count; i++) {
- final View child = navigationView.getChildAt(i);
- if (child != null && child instanceof ListView) {
- final ListView menuView = (ListView) child;
- final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
- final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
- wrapped.notifyDataSetChanged();
- }
- }
- }
-
- /*
- Crea una secuencia de caracteres de 8 digitos aleatorios (incluye mayusculas, minisculas y numeros).
- */
- public String makePassword(){
- Random r = new Random();
- String rnd = "";
- for (int i = 0; i < 8; i++){
- int a = r.nextInt(3);
- char b;
- if (a == 0){
- b = (char)(66 + r.nextInt(25));
- }else if (a == 1){
- b = (char)(97 + r.nextInt(25));
- }else{
- b = (char) (48 + r.nextInt(9));
- }
- rnd = rnd + b;
- }
- return rnd;
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/RecentPostAdapter.java b/app/src/main/java/org/bienvenidoainternet/baiparser/RecentPostAdapter.java
deleted file mode 100644
index b3938a9..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/RecentPostAdapter.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.content.Context;
-import android.text.Html;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
-
-import org.bienvenidoainternet.baiparser.structure.BoardItem;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.EnumSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class RecentPostAdapter extends ArrayAdapter {
-
- public RecentPostAdapter(Context context, List objects) {
- super(context, 0, objects);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- LayoutInflater inflater = (LayoutInflater)getContext()
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View listItemView = convertView;
- if (null == convertView) {
- listItemView = inflater.inflate(
- R.layout.recentpost_item,
- parent,
- false);
- }
- final BoardItem postItem = getItem(position);
- TextView rp_message = (TextView) listItemView.findViewById(R.id.rp_message);
- TextView rp_title = (TextView) listItemView.findViewById(R.id.rp_title);
- TextView rp_timediff = (TextView) listItemView.findViewById(R.id.rp_timediff);
- if (postItem.getParentBoard() != null){
- rp_title.setText(postItem.getParentBoard().getBoardName() + ": " + postItem.getSubject());
- }else{
- rp_title.setText(postItem.getSubject());
- }
- rp_message.setText(Html.fromHtml(postItem.getMessage()));
- Map timeDiff = computeDiff(new Date(postItem.getTimeStamp() * 1000L), new Date(System.currentTimeMillis()));
- String strTimeDiff = "";
- if (timeDiff.get(TimeUnit.SECONDS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.SECONDS) + (timeDiff.get(TimeUnit.SECONDS) == 1 ? " segundo" : " segundos");
- }
-
- if (timeDiff.get(TimeUnit.MINUTES) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.MINUTES) + (timeDiff.get(TimeUnit.MINUTES) == 1 ? " minuto" : " minutos");
- }
-
- if (timeDiff.get(TimeUnit.HOURS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.HOURS) + (timeDiff.get(TimeUnit.HOURS) == 1 ? " hora" : " horas");
- }
-
- if (timeDiff.get(TimeUnit.DAYS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.DAYS) + (timeDiff.get(TimeUnit.DAYS) == 1 ? " día" : " días");
- }
- rp_timediff.setText(strTimeDiff);
-
-
- return listItemView;
- }
-
-
- public static Map computeDiff(Date date1, Date date2) {
- long diffInMillies = date2.getTime() - date1.getTime();
- List units = new ArrayList(EnumSet.allOf(TimeUnit.class));
- Collections.reverse(units);
- Map result = new LinkedHashMap();
- long milliesRest = diffInMillies;
- for ( TimeUnit unit : units ) {
- long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
- long diffInMilliesForUnit = unit.toMillis(diff);
- milliesRest = milliesRest - diffInMilliesForUnit;
- result.put(unit,diff);
- }
- return result;
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
deleted file mode 100644
index 2a3ca24..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java
+++ /dev/null
@@ -1,370 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.koushikdutta.async.future.FutureCallback;
-import com.koushikdutta.ion.Ion;
-
-import org.bienvenidoainternet.baiparser.structure.Board;
-import org.bienvenidoainternet.baiparser.structure.BoardItem;
-import org.w3c.dom.Document;
-
-import java.io.File;
-
-import utils.ContentProviderUtils;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class ResponseActivity extends AppCompatActivity {
-
- private BoardItem theReply = null;
- private SharedPreferences settings;
- private String password;
- private String selectedFile = "";
- private final int PICK_IMAGE = 1;
- private boolean quoting = false, newthread = false;
- EditText filePath;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ThemeManager tm = new ThemeManager(this);
- this.setTheme(tm.getThemeForActivity());
- setContentView(R.layout.activity_response);
-
- settings = PreferenceManager.getDefaultSharedPreferences(this);
- password = settings.getString("pref_password", "12345678");
-
- if (savedInstanceState != null){
- this.theReply = savedInstanceState.getParcelable("theReply");
- this.quoting = savedInstanceState.getBoolean("quoting");
- this.newthread = savedInstanceState.getBoolean("newthread");
- }
- if (getIntent().getExtras() != null){
- this.theReply = getIntent().getParcelableExtra("theReply");
- this.quoting = getIntent().getBooleanExtra("quoting", false);
- this.newthread = getIntent().getBooleanExtra("newthread", false);
- }
-
- if (newthread){
- getSupportActionBar().setTitle("Nuevo hilo");
- getSupportActionBar().setSubtitle(theReply.getParentBoard().getBoardName());
- }else{
- getSupportActionBar().setTitle("Respondiendo");
- }
-
- TextView txtFilePath = (TextView) findViewById(R.id.txtFilePath);
- Button btnSelectFile = (Button) findViewById(R.id.btnSelectFiles);
- TextView txtThreadSubject = (TextView) findViewById(R.id.txtThreadSubject);
-
- txtThreadSubject.setVisibility(newthread ? View.VISIBLE : View.GONE);
-
- if (theReply != null && quoting){
- TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
- if (theReply.getParentBoard().getBoardType() == 1){ // BBS
- txtMessage.setText(">>" + theReply.getBbsId());
- }else{
- txtMessage.setText(">>" + theReply.getId());
- }
- }else if (theReply != null){
- txtFilePath.setVisibility(theReply.getParentBoard().isCanAttachFiles() ? View.VISIBLE : View.GONE);
- btnSelectFile.setVisibility(theReply.getParentBoard().isCanAttachFiles() ? View.VISIBLE : View.GONE);
- }
-
- LinearLayout layoutProcess = (LinearLayout)findViewById(R.id.layoutPostProcess);
- layoutProcess.setVisibility(View.GONE);
- filePath = (EditText) findViewById(R.id.txtFilePath);
-
- Button bBold = (Button) findViewById(R.id.buttonBold);
- Button bStrike = (Button) findViewById(R.id.buttonStrike);
- Button bList = (Button) findViewById(R.id.buttonList);
- Button bCode = (Button) findViewById(R.id.buttonCode);
- Button bUnder = (Button) findViewById(R.id.buttonUnderline);
- Button bItalic = (Button) findViewById(R.id.buttonItalic);
- Button select = (Button) findViewById(R.id.btnSelectFiles);
-
- bBold.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- applyTag("b");
- }
- });
- bItalic.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- applyTag("i");
- }
- });
- bStrike.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- applyTag("strike");
- }
- });
- bList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- applyTag("ul");
- }
- });
- bCode.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- applyTag("code");
- }
- });
- bUnder.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- applyTag("u");
- }
- });
-
- select.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);
- startActivityForResult(Intent.createChooser(intent, "Seleccionar Archivo"), PICK_IMAGE);
- }
- });
-
- }
-
- private void applyTag(String tag){
- TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
- if (txtMessage.getSelectionStart() == -1){
- txtMessage.setText(txtMessage.getText() + "<" + tag + ">" + tag +">");
- }else{
- String s = txtMessage.getText().toString();
- String a = s.substring(0, txtMessage.getSelectionStart());
- String b = s.substring(txtMessage.getSelectionStart(), txtMessage.getSelectionEnd());
- String c = s.substring(txtMessage.getSelectionEnd(), txtMessage.getText().length());
- txtMessage.setText(a + "<" + tag + ">" + b + "" + tag + ">" + c);
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_replyform, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.action_form_reply){
- TextView txtName = (TextView) findViewById(R.id.txtPosterName);
- TextView txtEmail = (TextView) findViewById(R.id.txtEmail);
- TextView txtMessage = (TextView) findViewById(R.id.txtResponse);
- TextView txtThreadSubject = (TextView) findViewById(R.id.txtThreadSubject);
- makePost(txtName.getText().toString(), txtEmail.getText().toString(), txtMessage.getText().toString(), txtThreadSubject.getText().toString());
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
- Uri selectedImage = data.getData();
- String picturePath = ContentProviderUtils.getPath(getApplicationContext(), selectedImage);
- selectedFile = picturePath;
- filePath.setText(picturePath);
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- }
-
- private void makePost(String name, String email, String message, String subject){
- int parentId = theReply.realParentId();
- // Si el parentId = 0 && subject != "" ==> Nuevo hilo
- if (newthread){
- parentId = 0;
- }
- LinearLayout layoutProcess = (LinearLayout)findViewById(R.id.layoutPostProcess);
- layoutProcess.setVisibility(View.VISIBLE);
- final RelativeLayout formSendPost = (RelativeLayout) findViewById(R.id.layoutForm);
- formSendPost.setVisibility(View.GONE);
- ProgressBar progess = (ProgressBar) findViewById(R.id.barPosting);
- final TextView err = (TextView)findViewById(R.id.txtPostingState);
- err.setText("");
- File up = new File(selectedFile);
-
- if (newthread){
- if (selectedFile.isEmpty()){
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/cgi/post")
- .setLogging("posting", Log.VERBOSE)
- .uploadProgressBar(progess)
- .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
- .setMultipartParameter("password", password)
- .setMultipartParameter("fielda", name)
- .setMultipartParameter("fieldb", email)
- .setMultipartParameter("name", "")
- .setMultipartParameter("email", "")
- .setMultipartParameter("message", message)
- .setMultipartParameter("subject", subject)
- .setMultipartParameter("noimage", "on")
- .asString()
- .setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, String result) {
- Log.v("sendPost", result);
- if (e != null) {
- Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
- formSendPost.setVisibility(View.VISIBLE);
- err.setText("Error: " + e.getMessage());
- e.printStackTrace();
- } else {
- if (result.contains("ERROR : Flood detectado.")){
- Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
- }else{
- Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
- }
- finish();
- }
- }
- });
- }else{
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/cgi/post")
- .uploadProgressBar(progess)
- .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
- .setMultipartParameter("password", password)
- .setMultipartParameter("fielda", name)
- .setMultipartParameter("fieldb", email)
- .setMultipartParameter("name", "")
- .setMultipartParameter("email", "")
- .setMultipartParameter("message", message)
- .setMultipartParameter("subject", subject)
- .setMultipartFile("file", up)
- .asString()
- .setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, String result) {
- Log.v("sendPost", result);
- if (e != null){
- Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
- formSendPost.setVisibility(View.VISIBLE);
- err.setText("Error: " + e.getMessage());
- e.printStackTrace();
- }else{
- if (result.contains("ERROR : Flood detectado.")){
- Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
- }else{
- Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
- }
- finish();
- }
- }
- });
- }
- }else{
- if (selectedFile.isEmpty()){
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/cgi/post")
- .setLogging("posting", Log.VERBOSE)
- .uploadProgressBar(progess)
- .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
- .setMultipartParameter("parent", String.valueOf(parentId))
- .setMultipartParameter("password", password)
- .setMultipartParameter("fielda", name)
- .setMultipartParameter("fieldb", email)
- .setMultipartParameter("name", "")
- .setMultipartParameter("email", "")
- .setMultipartParameter("message", message)
- .setMultipartParameter("subject", subject)
- .asString()
- .setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, String result) {
- Log.v("sendPost", result);
- if (e != null) {
- Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
- formSendPost.setVisibility(View.VISIBLE);
- err.setText("Error: " + e.getMessage());
- e.printStackTrace();
- } else {
- if (result.contains("ERROR : Flood detectado.")){
- Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
- }else{
- Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
- }
- finish();
- }
- }
- });
- }else{
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/cgi/post")
- .uploadProgressBar(progess)
- .setMultipartParameter("board", theReply.getParentBoard().getBoardDir())
- .setMultipartParameter("parent", String.valueOf(parentId))
- .setMultipartParameter("password", password)
- .setMultipartParameter("fielda", name)
- .setMultipartParameter("fieldb", email)
- .setMultipartParameter("name", "")
- .setMultipartParameter("email", "")
- .setMultipartParameter("message", message)
- .setMultipartParameter("subject", subject)
- .setMultipartFile("file", up)
- .asString()
- .setCallback(new FutureCallback() {
- @Override
- public void onCompleted(Exception e, String result) {
- Log.v("sendPost", result);
- if (e != null){
- Toast.makeText(getApplicationContext(), "Ha ocurrido un error! ;_;", Toast.LENGTH_LONG).show();
- formSendPost.setVisibility(View.VISIBLE);
- err.setText("Error: " + e.getMessage());
- e.printStackTrace();
- }else{
- if (result.contains("ERROR : Flood detectado.")){
- Toast.makeText(getApplicationContext(), "Error: Flood detectado.", Toast.LENGTH_LONG).show();
- }else{
- Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show();
- }
- finish();
- }
- }
- });
- }
- }
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
deleted file mode 100644
index 4a16139..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/SettingsActivity.java
+++ /dev/null
@@ -1,205 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.os.Build;
-import android.os.Bundle;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceFragment;
-import android.preference.PreferenceManager;
-import android.support.v7.app.ActionBar;
-import android.view.MenuItem;
-
-import java.util.List;
-
-/**
- * A {@link PreferenceActivity} that presents a set of application settings. On
- * handset devices, settings are presented as a single list. On tablets,
- * settings are split by category, with category headers shown to the left of
- * the list of settings.
- *
- * See
- * Android Design: Settings for design guidelines and the Settings
- * API Guide for more information on developing a Settings UI.
- */
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class SettingsActivity extends AppCompatPreferenceActivity {
- /**
- * A preference value change listener that updates the preference's summary
- * to reflect its new value.
- */
- private static boolean requireReset = false;
- private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object value) {
- String stringValue = value.toString();
-
- if (preference instanceof ListPreference) {
- // For list preferences, look up the correct display value in
- // the preference's 'entries' list.
- ListPreference listPreference = (ListPreference) preference;
- int index = listPreference.findIndexOfValue(stringValue);
-
- // Set the summary to reflect the new value.
- preference.setSummary(
- index >= 0
- ? listPreference.getEntries()[index]
- : null);
-
- }else {
- // For all other preferences, set the summary to the value's
- // simple string representation.
- preference.setSummary(stringValue);
- }
- System.out.println(preference.getKey());
- return true;
- }
- };
-
- /**
- * Helper method to determine if the device has an extra-large screen. For
- * example, 10" tablets are extra-large.
- */
- private static boolean isXLargeTablet(Context context) {
- return (context.getResources().getConfiguration().screenLayout
- & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
- }
-
- /**
- * Binds a preference's summary to its value. More specifically, when the
- * preference's value is changed, its summary (line of text below the
- * preference title) is updated to reflect the value. The summary is also
- * immediately updated upon calling this method. The exact display format is
- * dependent on the type of preference.
- *
- * @see #sBindPreferenceSummaryToValueListener
- */
- private static void bindPreferenceSummaryToValue(Preference preference) {
- // Set the listener to watch for value changes.
- preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
- requireReset = true;
- // Trigger the listener immediately with the preference's
- // current value.
- sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
- PreferenceManager
- .getDefaultSharedPreferences(preference.getContext())
- .getString(preference.getKey(), ""));
- }
-
- @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();
- }
-
- /**
- * Set up the {@link android.app.ActionBar}, if the API is available.
- */
- private void setupActionBar() {
- ActionBar actionBar = getSupportActionBar();
-
- if (actionBar != null) {
- // Show the Up button in the action bar.
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onIsMultiPane() {
- return isXLargeTablet(this);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public void onBuildHeaders(List target) {
-// loadHeadersFromResource(R.xml.pref_headers, target);
- }
-
- /**
- * This method stops fragment injection in malicious applications.
- * Make sure to deny any unknown fragments here.
- */
- protected boolean isValidFragment(String fragmentName) {
- return PreferenceFragment.class.getName().equals(fragmentName)
- || GeneralPreferenceFragment.class.getName().equals(fragmentName)
- ;
- }
-
- @Override
- public void onBackPressed() {
- Intent returnIntent = new Intent();
- returnIntent.putExtra("result", requireReset);
- setResult(Activity.RESULT_OK,returnIntent);
- finish();
- super.onBackPressed();
- }
-
- /**
- * This fragment shows general preferences only. It is used when the
- * activity is showing a two-pane settings UI.
- */
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public class GeneralPreferenceFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences);
- setHasOptionsMenu(true);
-
- // Bind the summaries of EditText/List/Dialog/Ringtone preferences
- // to their values. When their values change, their summaries are
- // updated to reflect the new value, per the Android Design
- // guidelines.
-// bindPreferenceSummaryToValue(findPreference("example_text"));
- bindPreferenceSummaryToValue(findPreference("pref_theme"));
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- if (id == android.R.id.home) {
-// startActivity(new Intent(getActivity(), SettingsActivity.class));
- Intent returnIntent = new Intent();
- returnIntent.putExtra("result",requireReset);
- setResult(Activity.RESULT_OK,returnIntent);
- finish();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
deleted file mode 100644
index d223773..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ThemeManager.java
+++ /dev/null
@@ -1,140 +0,0 @@
-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;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class ThemeManager {
- private int currentThemeId;
- 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 = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.sageColor});
- return a.getColor(0, Color.CYAN);
- }
-
- public int getMarginColor(){
- TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.marginColor});
- return a.getColor(0, Color.CYAN);
- }
-
- public void updateThemeId(int id){
- this.currentThemeId = id;
- }
-
- public int getNameColor() {
- TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.nameColor});
- return a.getColor(0, Color.CYAN);
- }
-
- public int getTripcodeColor() {
- TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.tripcodeColor});
- return a.getColor(0, Color.CYAN);
- }
-
- public int getPrimaryColor(){
- TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimary});
- return a.getColor(0, Color.CYAN);
- }
- public int getPrimaryDarkColor(){
- TypedArray a = activity.getTheme().obtainStyledAttributes(currentThemeId, new int[]{R.attr.colorPrimaryDark});
- return a.getColor(0, Color.CYAN);
- }
-
- public boolean 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
deleted file mode 100644
index 6a23280..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java
+++ /dev/null
@@ -1,337 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.graphics.Paint;
-import android.graphics.Typeface;
-import android.graphics.drawable.ColorDrawable;
-import android.net.Uri;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.text.Html;
-import android.text.Layout;
-import android.text.Spannable;
-import android.text.style.ClickableSpan;
-import android.text.style.URLSpan;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import org.bienvenidoainternet.baiparser.structure.BoardItem;
-import org.bienvenidoainternet.baiparser.structure.BoardItemFile;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.EnumSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class ThreadListAdapter extends ArrayAdapter{
- private Context context;
- private ThemeManager tm;
- Typeface monaFont;
- public boolean listThreads = false;
- private ArrayList boardItems = new ArrayList();
- private static final String EXTRA_FILELIST = "fileList";
-
- public ThreadListAdapter(Context context, List objects, ThemeManager tm) {
- super(context, 0, objects);
- this.context = context;
- this.tm = tm;
- monaFont = Typeface.createFromAsset(context.getAssets(), "fonts/mona.ttf");
- }
-
- public void updateBoardItems(ArrayList boardItems){
- this.boardItems = boardItems;
- }
-
- private String intToHexString(int i){
- return String.format("#%06X", (0xFFFFFF & i));
- }
- public static Map computeDiff(Date date1, Date date2) {
- long diffInMillies = date2.getTime() - date1.getTime();
- List units = new ArrayList(EnumSet.allOf(TimeUnit.class));
- Collections.reverse(units);
- Map result = new LinkedHashMap();
- long milliesRest = diffInMillies;
- for ( TimeUnit unit : units ) {
- long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
- long diffInMilliesForUnit = unit.toMillis(diff);
- milliesRest = milliesRest - diffInMilliesForUnit;
- result.put(unit,diff);
- }
- return result;
- }
- @Override
- public View getView(final int position, final View convertView, final ViewGroup parent){
- LayoutInflater inflater = (LayoutInflater)getContext()
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View listItemView = convertView;
- if (null == convertView) {
- listItemView = inflater.inflate(
- R.layout.thread_item,
- parent,
- false);
- }
-
- final BoardItem boardItem = getItem(position);
- if (boardItem == null){
- return listItemView;
- }
- SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getContext());
- boolean useMonaFont = settings.getBoolean("setting_monafont", true);
- boolean monaBbsOnly = settings.getBoolean("setting_mona_bbsonly", true);
- boolean resizeThumb = settings.getBoolean("setting_resize_thumbs", true);
- int marginColor = tm.getMarginColor();
- int sageColor = tm.getSageColor();
- int nameColor = tm.getNameColor();
- int tripcodeColor = tm.getTripcodeColor();
- String hexColor =intToHexString(boardItem.getIdColor());
- String sageHexColor = intToHexString(sageColor);
- String nameHexColor = intToHexString(nameColor);
- String tripcodeHexColor = intToHexString(tripcodeColor);
- String strId = "";
-
- TextView txtTitle = (TextView)listItemView.findViewById(R.id.lv_txtTitle);
- TextView txtPoster = (TextView)listItemView.findViewById(R.id.lv_txtPoster);
- TextView txtBody = (TextView) listItemView.findViewById(R.id.lv_txtBody);
- TextView txtReplies = (TextView) listItemView.findViewById(R.id.lv_txtReplyCounter);
- TextView txtFileInfo = (TextView) listItemView.findViewById(R.id.lv_txtFileInfo);
- ImageView ivMargin = (ImageView)listItemView.findViewById(R.id.ivMargin);
- ImageView ivThumb = (ImageView)listItemView.findViewById(R.id.ivThumb);
-
-// Log.v("resize", resizeThumb + "");
- if (resizeThumb){
- ivThumb.setScaleType(ImageView.ScaleType.FIT_XY);
- }else{
- ivThumb.setScaleType(ImageView.ScaleType.FIT_CENTER);
- }
-
- ivThumb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!boardItem.getThumb().isEmpty() && convertView != null){
- if (boardItem.getFile().endsWith(".webm") || boardItem.getFile().endsWith(".ogg") || boardItem.getFile().endsWith(".opus") || boardItem.getFile().endsWith(".swf") || boardItem.youtubeLink){
- Intent in;
- if (boardItem.youtubeLink){
- in = new Intent(Intent.ACTION_VIEW, Uri.parse(boardItem.youtubeURL));
- }else{
- in = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bienvenidoainternet.org/" + boardItem.getParentBoard().getBoardDir() + "/src/" + boardItem.getFile()));
- }
- in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- v.getContext().startActivity(in);
- }else {
- Intent in = new Intent(convertView.getContext(), ViewerActivity.class);
- Bundle b = new Bundle();
- ArrayList fileList = new ArrayList();
- int relativePosition = 0;
- for (int i = 0; i < boardItems.size(); i++){
- if (!boardItems.get(i).getFile().isEmpty()){
- if (boardItems.get(i).getFile().equals(boardItem.getFile())){
- relativePosition = fileList.size();
- }
- fileList.add(new BoardItemFile("http://bienvenidoainternet.org/" + boardItems.get(i).getParentBoard().getBoardDir() + "/src/" + boardItems.get(i).getFile(), boardItems.get(i).getFile(), boardItems.get(i).getParentBoard().getBoardDir()));
- }
- }
- b.putParcelableArrayList(EXTRA_FILELIST, fileList);
- b.putInt("position", relativePosition);
- in.putExtras(b);
- convertView.getContext().startActivity(in);
- }
- }
- }
- });
-
-
- ivMargin.setImageDrawable(new ColorDrawable(marginColor));
-
- if (useMonaFont){
- if (monaBbsOnly && boardItem.getParentBoard() != null){
- if (boardItem.getParentBoard().getBoardType() == 1){
- txtBody.setTypeface(monaFont);
- }
- }else{
- txtBody.setTypeface(monaFont);
- }
- }
-
- // Si es una respuesta ocultamos el margen
- if (boardItem.isReply){
- ivMargin.setVisibility(View.VISIBLE);
- txtTitle.setVisibility(View.GONE);
- }else{
- txtTitle.setVisibility(View.VISIBLE);
- ivMargin.setVisibility(View.GONE);
- txtTitle.setText(boardItem.getSubject());
- }
-
- // Si el fragmento esta viendo un hilo ocultamos los margenes
- if (listThreads){
- ivMargin.setVisibility(View.GONE);
- }
-
- // Si el item está eliminado activamos el soporte de
- if (boardItem.getDeletedCode() != 0){
- txtBody.setPaintFlags(txtBody.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
- }else{
- txtBody.setPaintFlags(txtBody.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
- }
-
-
- if (boardItem.getThumb().isEmpty()){
- ivThumb.setVisibility(View.GONE);
- }else{
- if (boardItem.getThumbBitmap() != null){
- ivThumb.setVisibility(View.VISIBLE);
- ivThumb.setImageBitmap(boardItem.getThumbBitmap());
- }else{
- ivThumb.setVisibility(View.VISIBLE);
- ivThumb.setImageResource(R.drawable.blank);
- }
- }
-
- Map timeDiff = computeDiff(new Date(boardItem.getTimeStamp() * 1000L), new Date(System.currentTimeMillis()));
- String strTimeDiff = "";
- if (timeDiff.get(TimeUnit.SECONDS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.SECONDS) + (timeDiff.get(TimeUnit.SECONDS) == 1 ? " segundo" : " segundos");
- }
- if (timeDiff.get(TimeUnit.MINUTES) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.MINUTES) + (timeDiff.get(TimeUnit.MINUTES) == 1 ? " minuto" : " minutos");
- }
- if (timeDiff.get(TimeUnit.HOURS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.HOURS) + (timeDiff.get(TimeUnit.HOURS) == 1 ? " hora" : " horas");
- }
- if (timeDiff.get(TimeUnit.DAYS) != 0){
- strTimeDiff = "Hace " + timeDiff.get(TimeUnit.DAYS) + (timeDiff.get(TimeUnit.DAYS) == 1 ? " día" : " días");
- }
-
-
- if (!boardItem.getPosterId().isEmpty() && !boardItem.getPosterId().equals("???")){
- strId = "[" + boardItem.getPosterId() + "] ";
- }
-
- // Si estamos mostrando un item de BBS, mostrar el ID_BBS en ves del ID del post
- int idToDisplay = 0;
- if (boardItem.getParentBoard() != null){
- if (boardItem.getParentBoard().getBoardType() == 1){
- idToDisplay = boardItem.getBbsId();
- }else{
- idToDisplay = boardItem.getId();
- }
- }else{
- idToDisplay = boardItem.getId();
- }
-
- txtPoster.setText(Html.fromHtml("No. " + idToDisplay + " por " + boardItem.getName() + " "
- + (boardItem.getTripcode() == "" ? "" : "" + boardItem.getTripcode() + "") + strId + " " + strTimeDiff));
- txtBody.setText(Html.fromHtml(boardItem.getMessage()));
-
- txtReplies.setVisibility(boardItem.isReply ? View.GONE : View.VISIBLE);
- txtReplies.setText(boardItem.getTotalReplies() + " respuestas " + (boardItem.getTotalFiles() == 0 ? "" : ", " + boardItem.getTotalFiles() + " archivos"));
-
- String fileExt = "";
- txtFileInfo.setVisibility(boardItem.getThumb().isEmpty() ? View.GONE : View.VISIBLE);
-
- if (!boardItem.getThumb().isEmpty() && boardItem.getThumb().startsWith("http")){
- txtFileInfo.setText("YOUTUBE");
- }else{
- if (!boardItem.getFile().isEmpty()){
- String[] pathSplit = boardItem.getFile().split("\\.");
- if (pathSplit.length != 0){
- fileExt = pathSplit[1].toUpperCase();
- }
- }
- txtFileInfo.setText(fileExt + " " + (boardItem.getFileSize() / 1024) + " KB " + boardItem.getThumbHeight() + "x" + boardItem.getThumbWidth());
- }
-
-
- // Trasnparentar items con sage
- if (convertView != null){
- if (settings.getBoolean("pref_transparent_sage", true)){
- convertView.setAlpha(boardItem.isSage() ? 0.75F : 1.0F);
- }
- }
-
- /*
- http://stackoverflow.com/questions/8558732/listview-textview-with-linkmovementmethod-makes-list-item-unclickable
- */
- txtBody.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- boolean ret = false;
- CharSequence text = ((TextView) v).getText();
- Spannable stext = Spannable.Factory.getInstance().newSpannable(text);
- TextView widget = (TextView) v;
- int action = event.getAction();
-
- if (action == MotionEvent.ACTION_UP ||
- action == MotionEvent.ACTION_DOWN) {
- int x = (int) event.getX();
- int y = (int) event.getY();
-
- x -= widget.getTotalPaddingLeft();
- y -= widget.getTotalPaddingTop();
-
- x += widget.getScrollX();
- y += widget.getScrollY();
-
- Layout layout = widget.getLayout();
- int line = layout.getLineForVertical(y);
- int off = layout.getOffsetForHorizontal(line, x);
-
- ClickableSpan[] link = stext.getSpans(off, off, ClickableSpan.class);
-/*04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: zonavip
-04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: read
-04-03 17:46:54.646 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: 43872
-04-03 17:46:54.650 13693-13693/org.bienvenidoainternet.baiparser V/URLParts: 25*/
- if (link.length != 0) {
- if (link[0] instanceof URLSpan){
- URLSpan uspan = (URLSpan) link[0];
- if (uspan.getURL().contains("/read/") && !uspan.getURL().contains("http")){
- String url = uspan.getURL();
- String[] parts = url.split("/");
- if (parts.length == 4 && listThreads){
- Log.v("ConvertView", convertView.getParent().toString());
- }
- return true;
- }
- }
- if (action == MotionEvent.ACTION_UP) {
- link[0].onClick(widget);
- }
- ret = true;
- }
- }
- return ret;
- }
- });
- return listItemView;
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
deleted file mode 100644
index 3da7f92..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package org.bienvenidoainternet.baiparser;
-
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.media.MediaScannerConnection;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Environment;
-import android.support.v4.view.ViewPager;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import org.bienvenidoainternet.baiparser.structure.BoardItemFile;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-
-import layout.FragmentImage;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class ViewerActivity extends AppCompatActivity implements FragmentImage.OnFragmentInteractionListener {
- private static final String EXTRA_FILELIST = "fileList", EXTRA_RELATIVEPOSITION = "position";
- private ViewPager imagePager;
- public ProgressBar barDownload;
- private int relativePosition = 0;
-
- public ArrayList fileList = new ArrayList();
- private CustomFragmentPagerAdapter pagerAdapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getIntent().getExtras() != null){
- fileList = getIntent().getParcelableArrayListExtra(EXTRA_FILELIST);
- relativePosition = getIntent().getIntExtra(EXTRA_RELATIVEPOSITION, 0);
- }
- setContentView(R.layout.activity_viewer);
- barDownload = (ProgressBar) findViewById(R.id.downloadProgressBar);
- imagePager = (ViewPager) findViewById(R.id.imagePager);
- this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
- for (int i = 0; i < fileList.size(); i++){
- Log.v("ImageViewer", fileList.get(i).toString());
- pagerAdapter.addFragment(FragmentImage.newInstance(fileList.get(i)));
- }
- imagePager.setAdapter(pagerAdapter);
- imagePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
- }
-
- @Override
- public void onPageSelected(int position) {
- getSupportActionBar().setSubtitle("(" + (position + 1) + " / " + fileList.size() + ") " + fileList.get(position).file);
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
-
- }
- });
- imagePager.setCurrentItem(relativePosition);
- this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- File baiDir = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/");
- if (!baiDir.exists()){
- baiDir.mkdir();
- }
- if (item.getItemId() == R.id.menu_save_img){
- BoardItemFile boardItemFile = fileList.get(imagePager.getCurrentItem());
- File to = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + boardItemFile.file);
- ContextWrapper cw = new ContextWrapper(getApplicationContext());
- File directory = cw.getDir("src", Context.MODE_PRIVATE);
- File fileSource = new File(directory, boardItemFile.boardDir + "_" + boardItemFile.file);
- try{
- InputStream in = new FileInputStream(fileSource);
- OutputStream out = new FileOutputStream(to);
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- Toast.makeText(getApplicationContext(), boardItemFile.file + " guardado.", Toast.LENGTH_LONG).show();
- MediaScannerConnection.scanFile(this, new String[]{to.getPath()}, new String[]{"image/jpeg"}, null);
- }catch (Exception e){
- e.printStackTrace();
- }
-
- }
- if (item.getItemId() == android.R.id.home) {
- onBackPressed();
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_viewer, menu);
- return true;
- }
-
- @Override
- public void onFragmentInteraction(Uri uri) {
-
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java
deleted file mode 100644
index 536f476..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.bienvenidoainternet.baiparser.structure;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-public class Board implements Parcelable{
- private String boardName, boardDir;
- private int boardType;
-
- public boolean isCanAttachFiles() {
- return canAttachFiles;
- }
-
- public void setCanAttachFiles(boolean canAttachFiles) {
- this.canAttachFiles = canAttachFiles;
- }
-
- private boolean canAttachFiles;
- public Board(String boardName, String boardDir, int boardType, boolean canAttachFiles){
- this.boardName = boardName;
- this.boardDir = boardDir;
- this.boardType = boardType;
- this.canAttachFiles = canAttachFiles;
- }
-
- public Board(Parcel in){
- this.boardName = in.readString();
- this.boardDir = in.readString();
- this.boardType = in.readInt();
- this.canAttachFiles = in.readByte() != 0;
- }
-
- public String getBoardDir() {
- return boardDir;
- }
-
- public String getBoardName() {
- return boardName;
- }
-
- public int getBoardType() {
- return boardType;
- }
-
- public static final Creator CREATOR = new Creator() {
- @Override
- public Board createFromParcel(Parcel in) {
- return new Board(in);
- }
-
- @Override
- public Board[] newArray(int size) {
- return new Board[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(boardName);
- dest.writeString(boardDir);
- dest.writeInt(boardType);
- dest.writeByte((byte)(canAttachFiles ? 1 : 0));
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java
deleted file mode 100644
index 8eb55e5..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java
+++ /dev/null
@@ -1,353 +0,0 @@
-package org.bienvenidoainternet.baiparser.structure;
-
-import android.graphics.Bitmap;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
-import org.jsoup.parser.Tag;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-public class BoardItem implements Parcelable {
- private String name = "";
- private String timestamp_formatted = "";
- private String thumb = "";
- private String tripcode = "";
- private String email = "";
- private String file = "";
- private String message = "";
- private String subject = "";
- private String posterId = "";
- public String youtubeURL = "", youtubeID = "";
- private int parentid = 0, id = 0, idcolor, totalreplies = 0, totalfiles, thumb_height, thumb_weight, filesize, deleted_code, bbs_id = 1, parentPostCount;
- private long timestamp = 0;
-
- private Bitmap thumbBitmap = null;
- public boolean downloadingThumb = false;
- public boolean isReply = false, isLocked = false, youtubeLink = false;
- private Board parentBoard = null;
-
- protected BoardItem(Parcel in) {
- name = in.readString();
- timestamp_formatted = in.readString();
- thumb = in.readString();
- tripcode = in.readString();
- email = in.readString();
- file = in.readString();
- message = in.readString();
- subject = in.readString();
- posterId = in.readString();
- youtubeURL = in.readString();
- youtubeID = in.readString();
- parentid = in.readInt();
- id = in.readInt();
- idcolor = in.readInt();
- totalreplies = in.readInt();
- totalfiles = in.readInt();
- thumb_height = in.readInt();
- thumb_weight = in.readInt();
- filesize = in.readInt();
- deleted_code = in.readInt();
- bbs_id = in.readInt();
- parentPostCount = in.readInt();
- timestamp = in.readLong();
- thumbBitmap = in.readParcelable(Bitmap.class.getClassLoader());
- downloadingThumb = in.readByte() != 0;
- isReply = in.readByte() != 0;
- isLocked = in.readByte() != 0;
- youtubeLink = in.readByte() != 0;
- parentBoard = in.readParcelable(Board.class.getClassLoader());
- }
-
- public static final Creator CREATOR = new Creator() {
- @Override
- public BoardItem createFromParcel(Parcel in) {
- return new BoardItem(in);
- }
-
- @Override
- public BoardItem[] newArray(int size) {
- return new BoardItem[size];
- }
- };
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String getFile() {
- return file;
- }
-
- public void setFile(String file) {
- this.file = file;
- }
-
- public int getFileSize() {
- return filesize;
- }
-
- public void setFilesize(int filesize) {
- this.filesize = filesize;
- }
-
- public int getIdColor() {
- return idcolor;
- }
-
- public void setIdColor(int idcolor) {
- this.idcolor = idcolor;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- Document msg = Jsoup.parse(message);
- if (!msg.getElementsByClass("yt").isEmpty()){
- Element you = msg.getElementsByClass("yt").first();
- if (this.getFile().isEmpty()){
- this.thumb = you.getElementsByTag("img").attr("src");
- String[] parts = thumb.split("/");
- this.youtubeLink = true;
- this.youtubeURL = "https://www.youtube.com/watch?v=" + parts[4];
- this.youtubeID = parts[4];
- Log.v("ID", youtubeID);
- }
- }
- msg.select("img[src]").remove();
- msg.select("span[class=unkfunc]").tagName("font").attr("color", "#8fb56c").wrap("");
- msg.select("div[class=yt]").wrap("");
- this.message = msg.html();
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Board getParentBoard() {
- return parentBoard;
- }
-
- public void setParentBoard(Board parentBoard) {
- this.parentBoard = parentBoard;
- }
-
- public int getParentId() {
- return parentid;
- }
-
- public void setParentId(int parentid) {
- this.parentid = parentid;
- }
-
- public int getParentPostCount() {
- return parentPostCount;
- }
-
- public void setParentPostCount(int parentPostCount) {
- this.parentPostCount = parentPostCount;
- }
-
- public String getPosterId() {
- return posterId;
- }
-
- public void setPosterId(String posterId) {
- this.posterId = posterId;
- }
-
- public String getSubject() {
- return subject;
- }
-
- public void setSubject(String subject) {
- this.subject = subject;
- }
-
- public String getThumb() {
- return thumb;
- }
-
- public void setThumb(String thumb) {
- this.thumb = thumb;
- }
-
- public int getThumbHeight() {
- return thumb_height;
- }
-
- public void setThumbHeight(int thumb_height) {
- this.thumb_height = thumb_height;
- }
-
- public int getThumbWidth() {
- return thumb_weight;
- }
-
- public void setThumbWidth(int thumb_weight) {
- this.thumb_weight = thumb_weight;
- }
-
- public Bitmap getThumbBitmap() {
- return thumbBitmap;
- }
-
- public void setThumbBitmap(Bitmap thumbBitmap) {
- this.thumbBitmap = thumbBitmap;
- }
-
- public long getTimeStamp() {
- return timestamp;
- }
-
- public void setTimeStamp(long timestamp) {
- this.timestamp = timestamp;
- }
-
- public String getTimeStampFormatted() {
- return timestamp_formatted;
- }
-
- public void setTimeStampFormatted(String timestamp_formatted) {
- this.timestamp_formatted = timestamp_formatted;
- }
-
- public int getTotalFiles() {
- return totalfiles;
- }
-
- public void setTotalFiles(int totalfiles) {
- this.totalfiles = totalfiles;
- }
-
- public int getTotalReplies() {
- return totalreplies;
- }
-
- public void setTotalReplies(int totalreplies) {
- this.totalreplies = totalreplies;
- }
-
- public String getTripcode() {
- return tripcode;
- }
-
- public void setTripcode(String tripcode) {
- this.tripcode = tripcode;
- }
-
- public int getDeletedCode() {
- return deleted_code;
- }
-
- public void setDeletedCode(int deleted_code) {
- this.deleted_code = deleted_code;
- if (deleted_code == 1){
- this.message = "Eliminado por el usuario.";
- }else if (deleted_code == 2){
- this.message = "Eliminado por el Staff.";
- }
- }
-
- public int getBbsId() {
- return bbs_id;
- }
-
- public void setBbsId(int bbs_id) {
- this.bbs_id = bbs_id;
- }
-
- public int realParentId(){
- if (parentid == 0){
- return id;
- }
- return parentid;
- }
-
- public BoardItem() {
-
- }
-
- public boolean isSage(){
- return this.email.equals("sage");
- }
-
- public void setLockStatus(int i){
- this.isLocked = i == 0 ? false : true;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(name);
- dest.writeString(timestamp_formatted);
- dest.writeString(thumb);
- dest.writeString(tripcode);
- dest.writeString(email);
- dest.writeString(file);
- dest.writeString(message);
- dest.writeString(subject);
- dest.writeString(posterId);
- dest.writeString(youtubeURL);
- dest.writeString(youtubeID);
- dest.writeInt(parentid);
- dest.writeInt(id);
- dest.writeInt(idcolor);
- dest.writeInt(totalreplies);
- dest.writeInt(totalfiles);
- dest.writeInt(thumb_height);
- dest.writeInt(thumb_weight);
- dest.writeInt(filesize);
- dest.writeInt(deleted_code);
- dest.writeInt(bbs_id);
- dest.writeInt(parentPostCount);
- dest.writeLong(timestamp);
- dest.writeParcelable(thumbBitmap, flags);
- dest.writeByte((byte) (downloadingThumb ? 1 : 0));
- dest.writeByte((byte) (isReply ? 1 : 0));
- dest.writeByte((byte) (isLocked ? 1 : 0));
- dest.writeByte((byte) (youtubeLink ? 1 : 0));
- dest.writeParcelable(parentBoard, flags);
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItemFile.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItemFile.java
deleted file mode 100644
index b71cac4..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItemFile.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.bienvenidoainternet.baiparser.structure;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-public class BoardItemFile implements Parcelable{
- public String file;
- public String fileURL;
- public String boardDir;
-
- public BoardItemFile(String fileURL, String file, String boardDir){
- this.fileURL = fileURL;
- this.file = file;
- this.boardDir = boardDir;
- }
-
- protected BoardItemFile(Parcel in) {
- file = in.readString();
- fileURL = in.readString();
- boardDir = in.readString();
- }
-
- public static final Creator CREATOR = new Creator() {
- @Override
- public BoardItemFile createFromParcel(Parcel in) {
- return new BoardItemFile(in);
- }
-
- @Override
- public BoardItemFile[] newArray(int size) {
- return new BoardItemFile[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(file);
- dest.writeString(fileURL);
- dest.writeString(boardDir);
- }
-}
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java
deleted file mode 100644
index 9cf2319..0000000
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.bienvenidoainternet.baiparser.structure;
-
-import android.graphics.Color;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import org.bienvenidoainternet.baiparser.ThemeManager;
-
-import java.util.Random;
-
-/**
- * BaiApp - Bienvenido a internet Android Application
- * Copyright (C) 2016 Renard1911(https://github.com/Renard1911)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-public class ReplyID implements Parcelable{
- public String id;
- public int color;
- public ReplyID(String id, ThemeManager tm){
- this.id = id;
- Random r = new Random();
- if (tm.isDarkTheme()){
- this.color = Color.rgb(r.nextInt(125) + 127, r.nextInt(127) + 127, r.nextInt(127) + 127);
- }else{
- this.color = Color.rgb(r.nextInt(125), r.nextInt(127), r.nextInt(127));
- }
- }
-
- protected ReplyID(Parcel in) {
- id = in.readString();
- color = in.readInt();
- }
-
- public static final Creator CREATOR = new Creator() {
- @Override
- public ReplyID createFromParcel(Parcel in) {
- return new ReplyID(in);
- }
-
- @Override
- public ReplyID[] newArray(int size) {
- return new ReplyID[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(id);
- dest.writeInt(color);
- }
-}
--
cgit v1.2.1-18-gbd029