diff options
author | Renard | 2016-04-25 20:48:52 -0300 |
---|---|---|
committer | Renard | 2016-04-25 20:48:52 -0300 |
commit | 034e14235e987b30d0ebc181b2d24c632035c453 (patch) | |
tree | 96d59bf03e78f39c418fcce12cd3e2aadda04c8c /app/src/main/java | |
parent | e6e9b750c7061471b7b0b899001a1e6f3d354e10 (diff) | |
download | BaiApp-1.7.tar.gz BaiApp-1.7.tar.xz BaiApp-1.7.zip |
v1.7v1.7
Diffstat (limited to 'app/src/main/java')
7 files changed, 398 insertions, 125 deletions
diff --git a/app/src/main/java/layout/FragmentBoardItemList.java b/app/src/main/java/layout/FragmentBoardItemList.java index ba80ae5..feaf7a0 100644 --- a/app/src/main/java/layout/FragmentBoardItemList.java +++ b/app/src/main/java/layout/FragmentBoardItemList.java @@ -410,6 +410,11 @@ public class FragmentBoardItemList extends Fragment { void updateToolbar(String s); void hideActionButton(); void showActionButton(); + void onThreadList(); + + void onThread(); + + void onRecentPosts(); } public void scrollToBotton(){ @@ -459,7 +464,6 @@ public class FragmentBoardItemList extends Fragment { item.setFile(thread.getString("file")); item.setFilesize(thread.getInt("file_size")); item.setId(thread.getInt("id")); - item.setMessage(thread.getString("message")); item.setName(thread.getString("name")); item.setSubject(thread.getString("subject")); item.setThumb(thread.getString("thumb")); @@ -470,6 +474,7 @@ public class FragmentBoardItemList extends Fragment { item.setTotalReplies(thread.getInt("total_replies")); item.setTripcode(thread.getString("tripcode")); item.setTimeStampFormatted(thread.getString("timestamp_formatted")); + item.setLockStatus(thread.getInt("locked")); if (item.getTimeStampFormatted().contains("ID")){ item.setPosterId(item.getTimeStampFormatted().split(" ")[1].replace("ID :", "")); } @@ -479,6 +484,7 @@ public class FragmentBoardItemList extends Fragment { if (currentBoard.getBoardType() == 1){ item.setBbsId(1); } + item.setMessage(thread.getString("message")); boardItems.add(item); if (!repliesForCatalog.equals("0")){ JSONArray replies = thread.getJSONArray("replies"); @@ -495,7 +501,7 @@ public class FragmentBoardItemList extends Fragment { reply.setFilesize(jReply.getInt("file_size")); reply.setId(jReply.getInt("id")); reply.setParentId(item.getId()); - reply.setMessage(jReply.getString("message")); + reply.setLockStatus(item.isLocked ? 1 : 0); reply.setName(jReply.getString("name")); reply.setSubject(jReply.getString("subject")); reply.setThumb(jReply.getString("thumb")); @@ -512,10 +518,12 @@ public class FragmentBoardItemList extends Fragment { reply.setIdColor(addReplyID(reply.getPosterId())); // reply.setTotalReplies(item.getTotalReplies()); + reply.setMessage(jReply.getString("message")); }else{ reply.setTimeStamp(jReply.getLong("timestamp")); reply.setId(jReply.getInt("id")); reply.isReply = true; + reply.setLockStatus(item.isLocked ? 1 : 0); } boardItems.add(reply); } @@ -528,6 +536,7 @@ public class FragmentBoardItemList extends Fragment { } listViewAdapter.notifyDataSetChanged(); listViewAdapter.updateBoardItems(boardItems); + mListener.onThreadList(); loadingMoreThreads = false; if (boardItems.isEmpty()){ mListener.updateToolbar(currentBoard, currentThread); @@ -575,7 +584,6 @@ public class FragmentBoardItemList extends Fragment { item.setFile(reply.getString("file")); item.setFilesize(reply.getInt("file_size")); item.setId(reply.getInt("id")); - item.setMessage(reply.getString("message")); item.setName(reply.getString("name")); item.setSubject(reply.getString("subject")); item.setThumb(reply.getString("thumb")); @@ -583,6 +591,7 @@ public class FragmentBoardItemList extends Fragment { item.setThumbWidth(reply.getInt("thumb_width")); item.setTimeStamp(reply.getLong("timestamp")); item.setParentId(json.getInt("id")); + item.setLockStatus(json.getInt("locked")); item.setTripcode(reply.getString("tripcode")); item.setTimeStampFormatted(reply.getString("timestamp_formatted")); if (item.getTimeStampFormatted().contains("ID")){ @@ -599,6 +608,7 @@ public class FragmentBoardItemList extends Fragment { item.setBbsId((item.getTotalReplies() - finalLimit + i) + 2); } } + item.setMessage(reply.getString("message")); } else { item.setId(reply.getInt("id")); @@ -626,6 +636,7 @@ public class FragmentBoardItemList extends Fragment { listViewBoardItems.setSelection(boardItems.size()); mListener.showActionButton(); } + mListener.onThread(); hideProgressBar(); } }); @@ -658,7 +669,6 @@ public class FragmentBoardItemList extends Fragment { recentPost.setFile(jPost.getString("file")); recentPost.setFilesize(jPost.getInt("file_size")); recentPost.setId(jPost.getInt("id")); - recentPost.setMessage(jPost.getString("message")); recentPost.setName(jPost.getString("name")); recentPost.setSubject(jPost.getString("subject")); recentPost.setThumb(jPost.getString("thumb")); @@ -672,6 +682,7 @@ public class FragmentBoardItemList extends Fragment { } recentPost.setParentBoard(((MainActivity) getActivity()).getBoardFromDir(jPost.getString("dir"))); recentPost.setParentId(jPost.getInt("parentid")); + recentPost.setMessage(jPost.getString("message")); boardItems.add(recentPost); } } catch (JSONException e1) { @@ -680,6 +691,7 @@ public class FragmentBoardItemList extends Fragment { } } recentPostAdapter.notifyDataSetChanged(); + mListener.onRecentPosts(); } }); @@ -696,7 +708,13 @@ public class FragmentBoardItemList extends Fragment { if (!directory.exists()){ directory.mkdir(); } - final File mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb()); + final File mypath; + if (bi.youtubeLink){ + mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.youtubeID); + }else{ + mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb()); + } + if (mypath.exists()){ try { Bitmap b = BitmapFactory.decodeStream(new FileInputStream(mypath)); @@ -713,8 +731,12 @@ public class FragmentBoardItemList extends Fragment { Log.i("getThumb", "Not using wifi"); return; } + String imgURL = "http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/thumb/" + bi.getThumb(); + if (bi.getThumb().startsWith("http")){ + imgURL = bi.getThumb(); + } Ion.with(getContext()) - .load("http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/thumb/" + bi.getThumb()) + .load(imgURL) .setLogging("getThumbnail", Log.INFO) .asBitmap() .setCallback(new FutureCallback<Bitmap>() { @@ -778,8 +800,8 @@ public class FragmentBoardItemList extends Fragment { public int addReplyID(String s){ - if (!idList.contains(new ReplyID(s))){ - idList.add(new ReplyID(s)); + if (!idList.contains(new ReplyID(s, tm))){ + idList.add(new ReplyID(s, tm)); } for (ReplyID r : idList){ if (r.id.equals(s)){return r.color;} diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java index 87ac15a..9a6a344 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java @@ -120,17 +120,37 @@ public class MainActivity extends AppCompatActivity fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (childFragment.currentBoard != null) { - if (!childFragment.boardItems.isEmpty()) { - try { - Intent in = new Intent(getApplicationContext(), ResponseActivity.class); - Bundle b = new Bundle(); - b.putParcelable("theReply", childFragment.boardItems.get(0)); - b.putBoolean("quoting", false); - in.putExtras(b); - startActivity(in); - } catch (Exception e) { - e.printStackTrace(); + 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(); + } } } } @@ -170,6 +190,7 @@ public class MainActivity extends AppCompatActivity @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()); @@ -178,14 +199,19 @@ public class MainActivity extends AppCompatActivity toolbar.setTitle("Post recientes"); toolbar.setSubtitle(""); } - fab.setVisibility(View.INVISIBLE); + 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.setVisibility(View.VISIBLE); + fab.show(); } } } @@ -367,6 +393,32 @@ public class MainActivity extends AppCompatActivity } } + @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"); @@ -384,7 +436,7 @@ public class MainActivity extends AppCompatActivity 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 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); } @@ -395,6 +447,10 @@ public class MainActivity extends AppCompatActivity } } }); + + Board parsedBoard = new Board("Testing Field", "polka", 1, true); + sub.add(parsedBoard.getBoardName()); + boardList.add(parsedBoard); refreshNavigator(); } diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java index 871aaf5..2a3ca24 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ResponseActivity.java @@ -54,7 +54,7 @@ public class ResponseActivity extends AppCompatActivity { private String password; private String selectedFile = ""; private final int PICK_IMAGE = 1; - private boolean quoting = false; + private boolean quoting = false, newthread = false; EditText filePath; @Override @@ -63,18 +63,34 @@ public class ResponseActivity extends AppCompatActivity { ThemeManager tm = new ThemeManager(this); this.setTheme(tm.getThemeForActivity()); setContentView(R.layout.activity_response); - getSupportActionBar().setTitle("Respondiendo"); + settings = PreferenceManager.getDefaultSharedPreferences(this); password = settings.getString("pref_password", "12345678"); 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 @@ -82,6 +98,9 @@ public class ResponseActivity extends AppCompatActivity { }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); @@ -89,39 +108,49 @@ public class ResponseActivity extends AppCompatActivity { 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) { - TextView txtMessage = (TextView) findViewById(R.id.txtResponse); - if (txtMessage.getSelectionStart() == -1){ - txtMessage.setText(txtMessage.getText() + "<b></b>"); - }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 + "<b>" + b + "</b>" + c); - } + applyTag("b"); } }); - Button bItalic = (Button) findViewById(R.id.buttonItalic); bItalic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TextView txtMessage = (TextView) findViewById(R.id.txtResponse); - if (txtMessage.getSelectionStart() == -1){ - txtMessage.setText(txtMessage.getText() + "<i></i>"); - }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 + "<i>" + b + "</i>" + c); - } + 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"); } }); - - Button select = (Button) findViewById(R.id.btnSelectFiles); select.setOnClickListener(new View.OnClickListener() { @Override @@ -135,6 +164,19 @@ public class ResponseActivity extends AppCompatActivity { } + 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); @@ -147,7 +189,8 @@ public class ResponseActivity extends AppCompatActivity { TextView txtName = (TextView) findViewById(R.id.txtPosterName); TextView txtEmail = (TextView) findViewById(R.id.txtEmail); TextView txtMessage = (TextView) findViewById(R.id.txtResponse); - makePost(txtName.getText().toString(), txtEmail.getText().toString(), txtMessage.getText().toString()); + TextView txtThreadSubject = (TextView) findViewById(R.id.txtThreadSubject); + makePost(txtName.getText().toString(), txtEmail.getText().toString(), txtMessage.getText().toString(), txtThreadSubject.getText().toString()); } return super.onOptionsItemSelected(item); } @@ -168,10 +211,11 @@ public class ResponseActivity extends AppCompatActivity { super.onSaveInstanceState(outState); } - private void makePost(String name, String email, String message){ - int parentId = theReply.getParentId(); - if (theReply.getParentId() == 0 || theReply.getParentId() == -1){ - parentId = theReply.getId(); + 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); @@ -181,62 +225,146 @@ public class ResponseActivity extends AppCompatActivity { final TextView err = (TextView)findViewById(R.id.txtPostingState); err.setText(""); File up = new File(selectedFile); - 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(theReply.realParentId())) - .setMultipartParameter("password", password) - .setMultipartParameter("fielda", name) - .setMultipartParameter("fieldb", email) - .setMultipartParameter("name", "") - .setMultipartParameter("email", "") - .setMultipartParameter("message", message) - .asString() - .setCallback(new FutureCallback<String>() { - @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 { - 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) - .setMultipartFile("file", up) - .asDocument() - .setCallback(new FutureCallback<Document>() { - @Override - public void onCompleted(Exception e, Document 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{ - Toast.makeText(getApplicationContext(), "Post enviado", Toast.LENGTH_LONG).show(); - finish(); + + 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<String>() { + @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<String>() { + @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<String>() { + @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<String>() { + @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/ThreadListAdapter.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java index 69c674e..6a23280 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ThreadListAdapter.java @@ -108,6 +108,7 @@ public class ThreadListAdapter extends ArrayAdapter<BoardItem>{ 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(); @@ -126,12 +127,24 @@ public class ThreadListAdapter extends ArrayAdapter<BoardItem>{ 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")){ - Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bienvenidoainternet.org/" + boardItem.getParentBoard().getBoardDir() + "/src/" + boardItem.getFile())); + 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 { @@ -244,14 +257,20 @@ public class ThreadListAdapter extends ArrayAdapter<BoardItem>{ txtReplies.setText(boardItem.getTotalReplies() + " respuestas " + (boardItem.getTotalFiles() == 0 ? "" : ", " + boardItem.getTotalFiles() + " archivos")); String fileExt = ""; - if (!boardItem.getFile().isEmpty()){ - String[] pathSplit = boardItem.getFile().split("\\."); - if (pathSplit.length != 0){ - fileExt = pathSplit[1].toUpperCase(); + txtFileInfo.setVisibility(boardItem.getThumb().isEmpty() ? View.GONE : View.VISIBLE); + + 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()); } - txtFileInfo.setVisibility(boardItem.getThumb().isEmpty() ? View.GONE : View.VISIBLE); - txtFileInfo.setText(fileExt + " " + (boardItem.getFileSize() / 1024) + " KB " + boardItem.getThumbHeight() + "x" + boardItem.getThumbWidth()); + // Trasnparentar items con sage if (convertView != null){ diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java index cb95e63..536f476 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/Board.java @@ -24,16 +24,28 @@ import android.os.Parcelable; public class Board implements Parcelable{ private String boardName, boardDir; private int boardType; - public Board(String boardName,String boardDir,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() { @@ -70,5 +82,6 @@ public class Board implements Parcelable{ 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 index b21d598..8eb55e5 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/BoardItem.java @@ -3,6 +3,12 @@ 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 @@ -31,12 +37,13 @@ public class BoardItem implements Parcelable { private String message = ""; private String subject = ""; private String posterId = ""; - private int parentid, id, idcolor, totalreplies = 0, totalfiles, thumb_height, thumb_weight, filesize, deleted_code, bbs_id = 1, parentPostCount; + 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; + public boolean isReply = false, isLocked = false, youtubeLink = false; private Board parentBoard = null; protected BoardItem(Parcel in) { @@ -49,6 +56,8 @@ public class BoardItem implements Parcelable { message = in.readString(); subject = in.readString(); posterId = in.readString(); + youtubeURL = in.readString(); + youtubeID = in.readString(); parentid = in.readInt(); id = in.readInt(); idcolor = in.readInt(); @@ -64,6 +73,8 @@ public class BoardItem implements Parcelable { 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()); } @@ -124,12 +135,22 @@ public class BoardItem implements Parcelable { } public void setMessage(String message) { - // TODO: Dar formato a los mensajes de otra forma - this.message = message.replace("<span class=\"unkfunc\">", "<font color=#85c749><i>"); - this.message = this.message.replace("</span>", "</i></font>"); - if (this.message.contains("<hr")){ - this.message = this.message.replace("<hr />", "<br><br><small><font color=#FF8800><i>") + "</i></small></font>"; + 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("<i></i>"); + msg.select("div[class=yt]").wrap("<font color=red'><i></i></font>"); + this.message = msg.html(); } public String getName() { @@ -288,6 +309,10 @@ public class BoardItem implements Parcelable { return this.email.equals("sage"); } + public void setLockStatus(int i){ + this.isLocked = i == 0 ? false : true; + } + @Override public int describeContents() { return 0; @@ -304,6 +329,8 @@ public class BoardItem implements Parcelable { dest.writeString(message); dest.writeString(subject); dest.writeString(posterId); + dest.writeString(youtubeURL); + dest.writeString(youtubeID); dest.writeInt(parentid); dest.writeInt(id); dest.writeInt(idcolor); @@ -319,6 +346,8 @@ public class BoardItem implements Parcelable { 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/ReplyID.java b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java index 2780e74..9cf2319 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/structure/ReplyID.java @@ -4,6 +4,8 @@ import android.graphics.Color; import android.os.Parcel; import android.os.Parcelable; +import org.bienvenidoainternet.baiparser.ThemeManager; + import java.util.Random; /** @@ -26,10 +28,14 @@ import java.util.Random; public class ReplyID implements Parcelable{ public String id; public int color; - public ReplyID(String id){ + public ReplyID(String id, ThemeManager tm){ this.id = id; Random r = new Random(); - this.color = Color.rgb(r.nextInt(125) + 127, r.nextInt(127) + 127, r.nextInt(127) + 127); + 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) { |