Legacy Code Publication
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk 32
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "pl.krzysiek.simplesocial"
|
||||||
|
minSdk 26
|
||||||
|
targetSdk 32
|
||||||
|
versionCode 12
|
||||||
|
versionName "1.09"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility mysqlConnectorJavaVersion
|
||||||
|
targetCompatibility mysqlConnectorJavaVersion
|
||||||
|
}
|
||||||
|
compileSdkVersion 32
|
||||||
|
buildToolsVersion '32.0.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||||
|
implementation 'com.google.android.material:material:1.5.0'
|
||||||
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||||
|
implementation "mysql:mysql-connector-java:5.1.49"
|
||||||
|
// implementation "mysql:mysql-connector-java:8.0.20"
|
||||||
|
implementation "commons-io:commons-io:2.11.0"
|
||||||
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
public void useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
assertEquals("pl.krzysiek.simplesocial", appContext.getPackageName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="pl.krzysiek.simplesocial">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
|
android:requestLegacyExternalStorage="true"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.SimpleSocial">
|
||||||
|
<activity
|
||||||
|
android:name=".Group"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".CommentsManagement"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".EditComments"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".EditPost"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".PostsManagement"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".Profile"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".Registration"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".EditProfile"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ThePost"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".NewPost"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".Homepage"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".Main"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
|
|
||||||
|
public class CommentsManagement extends AppCompatActivity {
|
||||||
|
|
||||||
|
Server server;
|
||||||
|
LinearLayout commentsList;
|
||||||
|
static int id;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_comments_management);
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit(View v){
|
||||||
|
Intent homepage = new Intent(this, Homepage.class);
|
||||||
|
startActivity(homepage);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad(){
|
||||||
|
Bundle data = getIntent().getExtras();
|
||||||
|
id = data.getInt("user");
|
||||||
|
commentsList = findViewById(R.id.commentsList);
|
||||||
|
server = new Server();
|
||||||
|
|
||||||
|
refreshComments();
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshComments(){
|
||||||
|
ResultSet rs = server.query("*", "comments", "id_author = " + id);
|
||||||
|
try{
|
||||||
|
while(rs.next()) {
|
||||||
|
generateComment(
|
||||||
|
rs.getInt(1),
|
||||||
|
rs.getInt(2),
|
||||||
|
rs.getInt(3),
|
||||||
|
rs.getString(4),
|
||||||
|
rs.getString(5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void generateComment(int id_comment, int id_post, int id_author, String dataUtworzenia, String tresc){
|
||||||
|
LinearLayout comment = new LinearLayout(commentsList.getContext());
|
||||||
|
LinearLayout.LayoutParams commentParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
commentParams.setMargins(0,4,8,4);
|
||||||
|
comment.setLayoutParams(commentParams);
|
||||||
|
comment.setId(View.generateViewId());
|
||||||
|
comment.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
|
||||||
|
LinearLayout buttonGroup = new LinearLayout(comment.getContext());
|
||||||
|
LinearLayout.LayoutParams btnGroupParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
buttonGroup.setLayoutParams(btnGroupParams);
|
||||||
|
buttonGroup.setId(View.generateViewId());
|
||||||
|
buttonGroup.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
buttonGroup.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
|
LinearLayout commentContent = new LinearLayout(comment.getContext());
|
||||||
|
LinearLayout.LayoutParams commentsParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
commentContent.setLayoutParams(commentsParams);
|
||||||
|
commentContent.setId(View.generateViewId());
|
||||||
|
commentContent.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
|
||||||
|
ContextThemeWrapper theme = new ContextThemeWrapper(buttonGroup.getContext(), R.style.Widget_MaterialComponents_Button);
|
||||||
|
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
buttonParams.setMargins(8,2,8,2);
|
||||||
|
|
||||||
|
Button editButton = new Button(theme);
|
||||||
|
editButton.setLayoutParams(buttonParams);
|
||||||
|
editButton.setId(View.generateViewId());
|
||||||
|
editButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.description_icon, 0,0,0);
|
||||||
|
editButton.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, EditComments.class);
|
||||||
|
intent.putExtra("comment", id_comment);
|
||||||
|
intent.putExtra("user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
Button deleteButton = new Button(theme);
|
||||||
|
deleteButton.setLayoutParams(buttonParams);
|
||||||
|
deleteButton.setId(View.generateViewId());
|
||||||
|
deleteButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.delete_icon,0,0,0);
|
||||||
|
deleteButton.setOnClickListener(view -> {
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
|
DialogInterface.OnClickListener alertDialog = (dialog, which) -> {
|
||||||
|
switch (which) {
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
server.delete("comments", "id_comment = " + id_comment);
|
||||||
|
Toast.makeText(this, "Komentarz został usunięty", Toast.LENGTH_SHORT).show();
|
||||||
|
commentsList.removeAllViewsInLayout();
|
||||||
|
refreshComments();
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
alert.setMessage("Czy na pewno chcesz usunąć ten komentarz?").setPositiveButton("Tak", alertDialog).setNegativeButton("Nie", alertDialog).show();
|
||||||
|
});
|
||||||
|
|
||||||
|
Button postButton = new Button(theme);
|
||||||
|
postButton.setLayoutParams(buttonParams);
|
||||||
|
postButton.setId(View.generateViewId());
|
||||||
|
postButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gotopost_icon,0,0,0);
|
||||||
|
postButton.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, ThePost.class);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
intent.putExtra("id_post", id_post);
|
||||||
|
intent.putExtra("from", "comment");
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
|
||||||
|
TextView commentToPost = new TextView(commentContent.getContext());
|
||||||
|
commentToPost.setId(View.generateViewId());
|
||||||
|
ResultSet rsPost = server.query("tytul", "posts", "id_post = " + id_post);
|
||||||
|
try{
|
||||||
|
while(rsPost.next())
|
||||||
|
commentToPost.setText("Komentarz do posta: \"" + rsPost.getString(1) + "\"");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView commentText = new TextView(commentContent.getContext());
|
||||||
|
commentText.setId(View.generateViewId());
|
||||||
|
commentText.setTextAppearance(R.style.TextAppearance_AppCompat_Medium);
|
||||||
|
commentText.setText(tresc);
|
||||||
|
|
||||||
|
TextView addedText = new TextView(commentContent.getContext());
|
||||||
|
addedText.setId(View.generateViewId());
|
||||||
|
addedText.setTextAppearance(R.style.TextAppearance_AppCompat_Body2);
|
||||||
|
addedText.setText(dataUtworzenia);
|
||||||
|
|
||||||
|
View divider = new View(commentsList.getContext());
|
||||||
|
TableRow.LayoutParams dividerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) getResources().getDisplayMetrics().density);
|
||||||
|
dividerParams.setMargins(32, 32, 32, 32);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(getColor(R.color.gray_400));
|
||||||
|
|
||||||
|
buttonGroup.addView(editButton);
|
||||||
|
buttonGroup.addView(postButton);
|
||||||
|
buttonGroup.addView(deleteButton);
|
||||||
|
commentContent.addView(commentToPost);
|
||||||
|
commentContent.addView(commentText);
|
||||||
|
commentContent.addView(addedText);
|
||||||
|
|
||||||
|
comment.addView(buttonGroup);
|
||||||
|
comment.addView(commentContent);
|
||||||
|
|
||||||
|
commentsList.addView(comment);
|
||||||
|
commentsList.addView(divider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class EditComments extends AppCompatActivity {
|
||||||
|
|
||||||
|
Server server;
|
||||||
|
Helpers helper;
|
||||||
|
|
||||||
|
EditText commentBox;
|
||||||
|
TextView postAuthor, postTitle, postText, postDate;
|
||||||
|
ImageView postImage;
|
||||||
|
|
||||||
|
int id_comment, id_post, id;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_edit_comments);
|
||||||
|
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad(){
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
|
||||||
|
commentBox = findViewById(R.id.commentBox);
|
||||||
|
postAuthor = findViewById(R.id.postAuthor);
|
||||||
|
postTitle = findViewById(R.id.postTitle);
|
||||||
|
postText = findViewById(R.id.postText);
|
||||||
|
postDate = findViewById(R.id.postDate);
|
||||||
|
|
||||||
|
postImage = findViewById(R.id.postImage);
|
||||||
|
|
||||||
|
Bundle datas = getIntent().getExtras();
|
||||||
|
id_comment = datas.getInt("comment");
|
||||||
|
id = datas.getInt("user");
|
||||||
|
|
||||||
|
ResultSet rs = server.query("posts.id_post, comments.tresc, users.username, posts.tytul, posts.tresc, posts.typPosta, posts.dataDodania", "comments, posts, users", "id_comment = " + id_comment + " AND posts.id_post = comments.id_post AND users.id = posts.id_autor");
|
||||||
|
try{
|
||||||
|
while(rs.next()){
|
||||||
|
id_post = rs.getInt(1);
|
||||||
|
commentBox.setText(rs.getString(2));
|
||||||
|
postAuthor.setText("Post użytkownika " + rs.getString(3));
|
||||||
|
postTitle.setText(rs.getString(4));
|
||||||
|
postText.setText(rs.getString(5));
|
||||||
|
if(rs.getInt(6) > 0){
|
||||||
|
ResultSet rsImage = server.query("picture", "pictures", "id_post = " + id_post);
|
||||||
|
while(rsImage.next())
|
||||||
|
postImage.setImageBitmap(helper.convertToBitmap(rsImage.getString(1)));
|
||||||
|
}
|
||||||
|
postDate.setText("Dodano " + rs.getString(7));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateComment(View v){
|
||||||
|
server.update("comments", "tresc = '" + commentBox.getText() + "'", "id_comment = " + id_comment);
|
||||||
|
Toast.makeText(this, "Komentarz został zaktualizowany", Toast.LENGTH_SHORT).show();
|
||||||
|
Intent intent = new Intent(this, ThePost.class);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
intent.putExtra("id_post", id_post);
|
||||||
|
intent.putExtra("from", "comment");
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit(View v){
|
||||||
|
Intent intent = new Intent(this, CommentsManagement.class);
|
||||||
|
intent.putExtra("user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Debug;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class EditPost extends AppCompatActivity {
|
||||||
|
|
||||||
|
static Server server;
|
||||||
|
static Helpers helper;
|
||||||
|
static int id;
|
||||||
|
static int id_post;
|
||||||
|
boolean changePic;
|
||||||
|
|
||||||
|
EditText title, text;
|
||||||
|
ImageView img;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_edit_post);
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad(){
|
||||||
|
getIds();
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
setObjects();
|
||||||
|
fillFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObjects(){
|
||||||
|
title = findViewById(R.id.postTitle);
|
||||||
|
text = findViewById(R.id.postText);
|
||||||
|
img = findViewById(R.id.postImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getIds(){
|
||||||
|
Bundle datas = getIntent().getExtras();
|
||||||
|
id_post = datas.getInt("post");
|
||||||
|
id = datas.getInt("user");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillFields(){
|
||||||
|
ResultSet rs = server.query("tytul, tresc, typPosta", "posts", "id_post = " + id_post);
|
||||||
|
try{
|
||||||
|
while(rs.next()){
|
||||||
|
title.setText(rs.getString(1));
|
||||||
|
text.setText(rs.getString(2));
|
||||||
|
if(rs.getInt(3) > 0){
|
||||||
|
ResultSet picRs = server.query("picture", "pictures", "pictures.id_post = " + id_post);
|
||||||
|
while(picRs.next()){
|
||||||
|
img.setImageBitmap(helper.convertToBitmap(picRs.getString(1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit(View v){
|
||||||
|
Intent intent = new Intent(this, PostsManagement.class);
|
||||||
|
intent.putExtra("user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveChanges(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
public class EditProfile extends AppCompatActivity {
|
||||||
|
|
||||||
|
static int id_user;
|
||||||
|
Server server;
|
||||||
|
|
||||||
|
TextView username, birthdateBox;
|
||||||
|
EditText nameBox, emailBox, phoneBox, actualPassBox, newPassBox, rpPassBox;
|
||||||
|
RadioButton maleBox, femaleBox;
|
||||||
|
Button deleteBtn;
|
||||||
|
|
||||||
|
DatePickerDialog.OnDateSetListener dateSetListener;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_edit_profile);
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLoad(){
|
||||||
|
Bundle fromIntent = getIntent().getExtras();
|
||||||
|
server = new Server();
|
||||||
|
|
||||||
|
id_user = fromIntent.getInt("id_user");
|
||||||
|
|
||||||
|
loadObjects();
|
||||||
|
fillItAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void loadObjects(){
|
||||||
|
username = findViewById(R.id.verifiedIcon);
|
||||||
|
nameBox = findViewById(R.id.nameBox);
|
||||||
|
emailBox = findViewById(R.id.emailBox);
|
||||||
|
phoneBox = findViewById(R.id.phoneBox);
|
||||||
|
actualPassBox = findViewById(R.id.actualPassBox);
|
||||||
|
newPassBox = findViewById(R.id.newPassBox);
|
||||||
|
rpPassBox = findViewById(R.id.rpPassBox);
|
||||||
|
birthdateBox = findViewById(R.id.birthdateBox);
|
||||||
|
|
||||||
|
maleBox = findViewById(R.id.maleBtn);
|
||||||
|
femaleBox = findViewById(R.id.femaleBtn);
|
||||||
|
|
||||||
|
deleteBtn = findViewById(R.id.deleteBtn);
|
||||||
|
|
||||||
|
dateSetListener = (datePicker, i, i1, i2) -> {
|
||||||
|
String year, month, day;
|
||||||
|
i1++;
|
||||||
|
month = (i1 < 10 ? "0" + i1 : Integer.toString(i1));
|
||||||
|
day = (i2 < 10 ? "0" + i2 : Integer.toString(i2));
|
||||||
|
year = Integer.toString(i);
|
||||||
|
|
||||||
|
birthdateBox.setText(year + "/" + month + "/" + day);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pickADate(View v){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
int year = cal.get(Calendar.YEAR);
|
||||||
|
int month = cal.get(Calendar.MONTH);
|
||||||
|
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
DatePickerDialog dialog = new DatePickerDialog(this, android.app.AlertDialog.THEME_HOLO_DARK, dateSetListener, year, month, day);
|
||||||
|
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillItAll(){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("username, nazwaWyswietlana, email, numerTelefonu, dataUrodzenia, plec", "users", "id = " + id_user);
|
||||||
|
while(rs.next()){
|
||||||
|
username.setText(rs.getString(1));
|
||||||
|
nameBox.setText(rs.getString(2));
|
||||||
|
emailBox.setText(rs.getString(3));
|
||||||
|
phoneBox.setText(rs.getString(4));
|
||||||
|
birthdateBox.setText(rs.getString(5));
|
||||||
|
|
||||||
|
if(rs.getBoolean(6))
|
||||||
|
maleBox.setChecked(true);
|
||||||
|
else
|
||||||
|
femaleBox.setChecked(true);
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exitEdit(View v){
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed(){
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateProfile(View v){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id", "users", "password = PASSWORD('" + actualPassBox.getText() + "') AND id = " + id_user);
|
||||||
|
if(!actualPassBox.getText().equals("")) {
|
||||||
|
while (rs.next()) {
|
||||||
|
if (rs.getInt(1) == id_user) {
|
||||||
|
server.update("users", "nazwaWyswietlana = '" + nameBox.getText() + "', email = '" + emailBox.getText() + "', numerTelefonu = '" + phoneBox.getText() + "', dataUrodzenia = '" + birthdateBox.getText() + "'", "id = " + id_user);
|
||||||
|
|
||||||
|
if(maleBox.isChecked())
|
||||||
|
server.update("users", "plec = 1", "id = " + id_user);
|
||||||
|
else
|
||||||
|
server.update("users", "plec = 0", "id = " + id_user);
|
||||||
|
|
||||||
|
Toast.makeText(this, "Profil został zaktualizowany!", Toast.LENGTH_SHORT).show();
|
||||||
|
if (newPassBox.getText() == rpPassBox.getText()) {
|
||||||
|
server.update("users", "password = PASSWORD('" + newPassBox.getText() + "')", "id = " + id_user);
|
||||||
|
Toast.makeText(this, "Hasło zostało zaktualizowane!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
} else
|
||||||
|
Toast.makeText(this, "Wpisz swoje obecne hasło, aby zaktualizować swój profil!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Wpisz swoje obecne hasło, aby zaktualizować swój profil!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteBtnAction(View v){
|
||||||
|
areYouSure();
|
||||||
|
}
|
||||||
|
|
||||||
|
void areYouSure(){
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(deleteBtn.getContext());
|
||||||
|
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
|
||||||
|
switch (which){
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
server.delete("posts", "id_autor = " + id_user);
|
||||||
|
server.delete("comments", "id_author = " + id_user);
|
||||||
|
Toast.makeText(deleteBtn.getContext(), "Konto zostało usunięte :(", Toast.LENGTH_SHORT).show();
|
||||||
|
server.delete("users", "id = " + id_user);
|
||||||
|
Intent intent = new Intent(deleteBtn.getContext(), Main.class);
|
||||||
|
finish();
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
Toast.makeText(deleteBtn.getContext(), "Uff... Fajnie, że zostajesz z nami :D", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
builder.setMessage("Czy na pewno chcesz usunąć konto? Wszystkie Twoje posty, komentarze oraz inne ślady znikną z serwisu. :/").setPositiveButton("Tak", dialogClickListener).setNegativeButton("Nie", dialogClickListener).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class GetEveryData extends AsyncTask<Integer, Void, String[][]> {
|
||||||
|
Helpers helper;
|
||||||
|
Server server;
|
||||||
|
public GetEveryData(Helpers help, Server srv){
|
||||||
|
helper = help;
|
||||||
|
server = srv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[][] doInBackground(Integer[] params){
|
||||||
|
String[][] table = new String[params.length][5];
|
||||||
|
for(int i = 0; i < params.length; i++){
|
||||||
|
ResultSet rs = server.query("posts.id_post, users.username, posts.tresc, posts.dataDodania, posts.tytul", "posts, users", "posts.id_post = " + params[i] + " AND users.id = posts.id_autor");
|
||||||
|
try{
|
||||||
|
while(rs.next()){
|
||||||
|
for(int j = 0; j < 5; j++){
|
||||||
|
table[i][j] = rs.getString(j + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String[][] table){
|
||||||
|
super.onPostExecute(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.media.Image;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class GetMeImage extends AsyncTask<String, Void, Bitmap> {
|
||||||
|
private final ImageView img;
|
||||||
|
Helpers helpers;
|
||||||
|
Server server;
|
||||||
|
public GetMeImage(ImageView image, Helpers helper, Server srv){
|
||||||
|
img = image;
|
||||||
|
helpers = helper;
|
||||||
|
server = srv;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Bitmap doInBackground(String... id_post){
|
||||||
|
Bitmap bmp = null;
|
||||||
|
try {
|
||||||
|
ResultSet rs = server.query("picture", "posts_pictures", "id_post = " + id_post[0]);
|
||||||
|
while(rs.next()){
|
||||||
|
bmp = helpers.convertToBitmap(rs.getString(1));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bitmap result){
|
||||||
|
super.onPostExecute(result);
|
||||||
|
img.setImageBitmap(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class Group extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_group);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.constraintlayout.motion.widget.Debug;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
public class Helpers extends AppCompatActivity {
|
||||||
|
|
||||||
|
final Server server = new Server();
|
||||||
|
Bitmap bmp;
|
||||||
|
|
||||||
|
public Bitmap convertToBitmap(String base64) {
|
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(base64);
|
||||||
|
return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThatPath(Uri uri, Context activity){
|
||||||
|
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||||||
|
String yourRealPath = null;
|
||||||
|
Cursor cursor = activity.getContentResolver().query(uri, filePathColumn, null, null, null);
|
||||||
|
if(cursor.moveToFirst()){
|
||||||
|
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||||
|
yourRealPath = cursor.getString(columnIndex);
|
||||||
|
} else
|
||||||
|
Debug.logStack("Błąd!", "Coś wyszło nie tak przy getThatPath. Linia 30 w Helpers", 1);
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
return yourRealPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String convertToBase64(Intent data, Context activity) {
|
||||||
|
String x = "";
|
||||||
|
try {
|
||||||
|
byte[] fileContent = org.apache.commons.io.FileUtils.readFileToByteArray(new File(getThatPath(data.getData(), activity)));
|
||||||
|
x = Base64.getEncoder().encodeToString(fileContent);
|
||||||
|
} catch (IOException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String GetDate(){
|
||||||
|
LocalDateTime dateTime = LocalDateTime.now();
|
||||||
|
return dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint({"SetTextI18n", "ResourceAsColor", "UseCompatLoadingForDrawables", "StaticFieldLeak"})
|
||||||
|
public void GeneratePosts(LinearLayout postsList, int id_user, Activity activity, Context context, String from, String id_post, String autor, String text, String title, String datetime){
|
||||||
|
boolean nsfw = false;
|
||||||
|
|
||||||
|
TableLayout table = new TableLayout(postsList.getContext());
|
||||||
|
TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
|
||||||
|
table.setId(View.generateViewId());
|
||||||
|
table.setLayoutParams(tableParams);
|
||||||
|
|
||||||
|
TableRow authorRow = new TableRow(table.getContext());
|
||||||
|
authorRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
TextView authorLabel = new TextView(authorRow.getContext());
|
||||||
|
authorLabel.setPadding(16,16,16,16);
|
||||||
|
authorLabel.setText(autor + " \nDodano: " + datetime);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
TableRow titleRow = new TableRow(table.getContext());
|
||||||
|
titleRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
TextView titleLabel = new TextView(titleRow.getContext());
|
||||||
|
titleLabel.setPadding(16,16,16,4);
|
||||||
|
titleLabel.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
titleLabel.setTextAppearance(R.style.TextAppearance_AppCompat_Large);
|
||||||
|
titleLabel.setMaxLines(2);
|
||||||
|
titleLabel.setTextSize(20f);
|
||||||
|
titleLabel.setText(title);
|
||||||
|
titleLabel.setOnClickListener(view -> {
|
||||||
|
Intent thePostIntent = new Intent(context, ThePost.class);
|
||||||
|
thePostIntent.putExtra("id_user", id_user);
|
||||||
|
thePostIntent.putExtra("id_post", id_post);
|
||||||
|
thePostIntent.putExtra("from", from);
|
||||||
|
activity.startActivity(thePostIntent);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
TableRow textRow = new TableRow(table.getContext());
|
||||||
|
textRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
TextView textLabel = new TextView(textRow.getContext());
|
||||||
|
textLabel.setPadding(16,4,16,16);
|
||||||
|
textLabel.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
textLabel.setMaxLines(5);
|
||||||
|
textLabel.setTextSize(20f);
|
||||||
|
textLabel.setText(text);
|
||||||
|
textLabel.setOnClickListener(view -> {
|
||||||
|
Intent thePostIntent = new Intent(context, ThePost.class);
|
||||||
|
thePostIntent.putExtra("id_user", id_user);
|
||||||
|
thePostIntent.putExtra("id_post", id_post);
|
||||||
|
thePostIntent.putExtra("from", from);
|
||||||
|
activity.startActivity(thePostIntent);
|
||||||
|
});
|
||||||
|
|
||||||
|
ImageView image = new ImageView(table.getContext());
|
||||||
|
try{
|
||||||
|
ResultSet haveImage = server.query("typPosta", "posts", "id_post = " + id_post);
|
||||||
|
while(haveImage.next()){
|
||||||
|
if(haveImage.getBoolean(1)){
|
||||||
|
TableLayout.LayoutParams layout = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
layout.setMargins(0, 16, 0, 32);
|
||||||
|
image.setLayoutParams(layout);
|
||||||
|
image.setAdjustViewBounds(true);
|
||||||
|
image.setId(View.generateViewId());
|
||||||
|
image.setMaxHeight(1920);
|
||||||
|
GetMeImage gmi = new GetMeImage(image, this, server);
|
||||||
|
gmi.doInBackground(id_post);
|
||||||
|
WeakReference<ImageView> imageViewWeakReference = new WeakReference<>(image);
|
||||||
|
new AsyncTask<String, Void, Bitmap>(){
|
||||||
|
@Override
|
||||||
|
protected Bitmap doInBackground(String... strings){
|
||||||
|
Bitmap bitmap = null;
|
||||||
|
try {
|
||||||
|
ResultSet rs = server.query("picture", "posts_pictures", "id_post = " + id_post);
|
||||||
|
while(rs.next()){
|
||||||
|
bitmap = convertToBitmap(rs.getString(1));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bitmap bitmap){
|
||||||
|
super.onPostExecute(bitmap);
|
||||||
|
if(bitmap != null){
|
||||||
|
ImageView weak = imageViewWeakReference.get();
|
||||||
|
if(weak != null)
|
||||||
|
weak.setImageBitmap(bitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
/*ResultSet getImage = server.query("picture", "posts_pictures", "id_post = " + id_post);
|
||||||
|
while (getImage.next()) {
|
||||||
|
image.setImageBitmap(convertToBitmap(getImage.getString(1)));*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
TableRow nsfwTag = new TableRow(table.getContext());
|
||||||
|
nsfwTag.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
nsfwTag.setGravity(Gravity.START);
|
||||||
|
|
||||||
|
ImageView nsfwIcon = new ImageView(nsfwTag.getContext());
|
||||||
|
nsfwIcon.setImageDrawable(context.getDrawable(R.drawable.warning));
|
||||||
|
nsfwIcon.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams iconLayout = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
iconLayout.setMargins(16,16,4,16);
|
||||||
|
nsfwIcon.setLayoutParams(iconLayout);
|
||||||
|
nsfwIcon.setBackgroundColor(Color.BLACK);
|
||||||
|
nsfwIcon.setMaxWidth(32);
|
||||||
|
|
||||||
|
TextView nsfwText = new TextView(nsfwTag.getContext());
|
||||||
|
nsfwText.setText("NSFW");
|
||||||
|
TableRow.LayoutParams textLayout = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
textLayout.setMargins(4,16,16,16);
|
||||||
|
nsfwText.setLayoutParams(textLayout);
|
||||||
|
|
||||||
|
nsfwTag.addView(nsfwIcon);
|
||||||
|
nsfwTag.addView(nsfwText);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
TableRow likesRow = new TableRow(table.getContext());
|
||||||
|
likesRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
ConstraintLayout inLikesRow = new ConstraintLayout(likesRow.getContext());
|
||||||
|
inLikesRow.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams inLikesRowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT, 1.0f);
|
||||||
|
inLikesRow.setLayoutParams(inLikesRowParams);
|
||||||
|
|
||||||
|
ContextThemeWrapper newContext = new ContextThemeWrapper(context, R.style.Widget_MaterialComponents_Button);
|
||||||
|
|
||||||
|
Button likesBtn = new Button(newContext);
|
||||||
|
likesBtn.setId(View.generateViewId());
|
||||||
|
ConstraintLayout.LayoutParams likeParams = new ConstraintLayout.LayoutParams((int) context.getResources().getDisplayMetrics().density * 70, ConstraintLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
likeParams.setMarginStart(8);
|
||||||
|
likeParams.startToStart = 0;
|
||||||
|
likeParams.topToTop = 0;
|
||||||
|
likeParams.bottomToBottom = 0;
|
||||||
|
likesBtn.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
|
TextView likesCount = new TextView(inLikesRow.getContext());
|
||||||
|
ConstraintLayout.LayoutParams likesCountParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
likesCountParams.startToEnd = likesBtn.getId();
|
||||||
|
likesCountParams.bottomToBottom = 0;
|
||||||
|
likesCountParams.topToTop = 0;
|
||||||
|
likesCountParams.setMarginStart(8);
|
||||||
|
likesCount.setGravity(Gravity.CENTER);
|
||||||
|
likesCount.setTextAppearance(R.style.TextAppearance_AppCompat_Large);
|
||||||
|
likesCount.setId(View.generateViewId());
|
||||||
|
likesCount.setLayoutParams(likesCountParams);
|
||||||
|
try {
|
||||||
|
ResultSet rs = server.query("COUNT(*)", "posts_likes", "id_post = " + id_post);
|
||||||
|
while(rs.next())
|
||||||
|
likesCount.setText(rs.getString(1));
|
||||||
|
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
likesBtn.setLayoutParams(likeParams);
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id_like", "posts_likes", "id_post = " + id_post + " AND id_user = " + id_user);
|
||||||
|
if(!rs.isBeforeFirst())
|
||||||
|
likesBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.like_icon, 0, 0, 0);
|
||||||
|
else
|
||||||
|
likesBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.liked_icon, 0,0,0);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
likesBtn.setOnClickListener(view -> {
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id_like", "posts_likes", "id_post = " + id_post + " AND id_user = " + id_user);
|
||||||
|
if(!rs.isBeforeFirst()) {
|
||||||
|
server.insert("posts_likes", "NULL, " + id_post + ", " + id_user + ", '" + GetDate() + "'");
|
||||||
|
likesBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.liked_icon, 0,0,0);
|
||||||
|
} else {
|
||||||
|
server.delete("posts_likes", "id_post = " + id_post + " AND id_user = " + id_user);
|
||||||
|
likesBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.like_icon, 0, 0, 0);
|
||||||
|
}
|
||||||
|
ResultSet rsLikes = server.query("COUNT(*)", "posts_likes", "id_post = " + id_post);
|
||||||
|
while(rsLikes.next())
|
||||||
|
likesCount.setText(rsLikes.getString(1));
|
||||||
|
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
View divider = new View(inLikesRow.getContext());
|
||||||
|
divider.setId(View.generateViewId());
|
||||||
|
ConstraintLayout.LayoutParams dividerParams = new ConstraintLayout.LayoutParams((int) context.getResources().getDisplayMetrics().density, ConstraintLayout.LayoutParams.MATCH_PARENT);
|
||||||
|
dividerParams.startToEnd = likesCount.getId();
|
||||||
|
dividerParams.topToTop = 0;
|
||||||
|
dividerParams.bottomToBottom = 0;
|
||||||
|
dividerParams.setMargins(16, 0, 0, 0);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(context.getColor(R.color.gray_600));
|
||||||
|
|
||||||
|
Button commentsBtn = new Button(newContext);
|
||||||
|
commentsBtn.setId(View.generateViewId());
|
||||||
|
ConstraintLayout.LayoutParams commentsParams = new ConstraintLayout.LayoutParams((int) context.getResources().getDisplayMetrics().density * 70, ConstraintLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
commentsParams.setMarginStart(16);
|
||||||
|
commentsParams.startToEnd = divider.getId();
|
||||||
|
commentsParams.topToTop = 0;
|
||||||
|
commentsParams.bottomToBottom = 0;
|
||||||
|
commentsBtn.setGravity(Gravity.CENTER);
|
||||||
|
commentsBtn.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.comment_icon,0);
|
||||||
|
commentsBtn.setLayoutParams(commentsParams);
|
||||||
|
commentsBtn.setOnClickListener(view ->{
|
||||||
|
Intent thePostIntent = new Intent(context, ThePost.class);
|
||||||
|
thePostIntent.putExtra("id_user", id_user);
|
||||||
|
thePostIntent.putExtra("id_post", id_post);
|
||||||
|
thePostIntent.putExtra("from", from);
|
||||||
|
activity.startActivity(thePostIntent);
|
||||||
|
});
|
||||||
|
|
||||||
|
View divider2 = new View(postsList.getContext());
|
||||||
|
TableRow.LayoutParams divider2Params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) context.getResources().getDisplayMetrics().density);
|
||||||
|
divider2Params.setMargins(32, 32, 32, 32);
|
||||||
|
divider2.setLayoutParams(divider2Params);
|
||||||
|
divider2.setBackgroundColor(context.getColor(R.color.gray_400));
|
||||||
|
|
||||||
|
try{
|
||||||
|
ResultSet checkNsfw = server.query("nsfw", "posts", "id_post = " + id_post);
|
||||||
|
while(checkNsfw.next()){
|
||||||
|
nsfw = checkNsfw.getBoolean(1);
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
titleRow.addView(titleLabel);
|
||||||
|
inLikesRow.addView(likesBtn);
|
||||||
|
inLikesRow.addView(likesCount);
|
||||||
|
inLikesRow.addView(divider);
|
||||||
|
inLikesRow.addView(commentsBtn);
|
||||||
|
likesRow.addView(inLikesRow);
|
||||||
|
textRow.addView(textLabel);
|
||||||
|
authorRow.addView(authorLabel);
|
||||||
|
|
||||||
|
table.addView(authorRow);
|
||||||
|
table.addView(titleRow);
|
||||||
|
|
||||||
|
if(!nsfw) {
|
||||||
|
table.addView(textRow);
|
||||||
|
table.addView(image);
|
||||||
|
} else {
|
||||||
|
table.addView(nsfwTag);
|
||||||
|
}
|
||||||
|
table.addView(likesRow);
|
||||||
|
postsList.addView(table);
|
||||||
|
postsList.addView(divider2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void GenerateComments(LinearLayout commentList, String autor, Context context, String tresc, String dataUtworzenia, TextView author){
|
||||||
|
LinearLayout comment = new LinearLayout(commentList.getContext());
|
||||||
|
LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
comment.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
comment.setId(View.generateViewId());
|
||||||
|
comment.setLayoutParams(linParams);
|
||||||
|
|
||||||
|
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
TableRow authorRow = new TableRow(comment.getContext());
|
||||||
|
authorRow.setId(View.generateViewId());
|
||||||
|
authorRow.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView authorText = new TextView(authorRow.getContext());
|
||||||
|
authorText.setId(View.generateViewId());
|
||||||
|
authorText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
authorText.setPadding(16, 16, 16, 4);
|
||||||
|
authorText.setText(autor + " odpowiedział " + author.getText());
|
||||||
|
|
||||||
|
TableRow content = new TableRow(comment.getContext());
|
||||||
|
content.setId(View.generateViewId());
|
||||||
|
content.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView contentText = new TextView(author.getContext());
|
||||||
|
contentText.setId(View.generateViewId());
|
||||||
|
contentText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
contentText.setPadding(16, 4, 16, 4);
|
||||||
|
contentText.setAutoLinkMask(Linkify.ALL);
|
||||||
|
contentText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
contentText.setText(tresc);
|
||||||
|
|
||||||
|
TableRow added = new TableRow(comment.getContext());
|
||||||
|
added.setId(View.generateViewId());
|
||||||
|
added.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView addedText = new TextView(author.getContext());
|
||||||
|
addedText.setId(View.generateViewId());
|
||||||
|
addedText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
addedText.setPadding(16, 4, 16, 16);
|
||||||
|
addedText.setText("Dodano " + dataUtworzenia);
|
||||||
|
|
||||||
|
View divider = new View(commentList.getContext());
|
||||||
|
TableRow.LayoutParams dividerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) context.getResources().getDisplayMetrics().density);
|
||||||
|
dividerParams.setMargins(32, 32, 32, 32);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(context.getColor(R.color.gray_400));
|
||||||
|
|
||||||
|
authorRow.addView(authorText);
|
||||||
|
content.addView(contentText);
|
||||||
|
added.addView(addedText);
|
||||||
|
|
||||||
|
comment.addView(authorRow);
|
||||||
|
comment.addView(content);
|
||||||
|
comment.addView(added);
|
||||||
|
|
||||||
|
commentList.addView(comment);
|
||||||
|
commentList.addView(divider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,473 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.text.InputFilter;
|
||||||
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.google.android.material.tabs.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
public class Homepage extends AppCompatActivity implements Serializable {
|
||||||
|
|
||||||
|
public static int id;
|
||||||
|
|
||||||
|
TextView loggedAs;
|
||||||
|
FloatingActionButton newPostBtn;
|
||||||
|
Button refreshBtn;
|
||||||
|
|
||||||
|
ScrollView homeView, menuView, searchView;
|
||||||
|
TabLayout navigationTab;
|
||||||
|
LinearLayout postsList, searchResults;
|
||||||
|
int posts = 0;
|
||||||
|
|
||||||
|
EditText searchBar;
|
||||||
|
ImageView avatarUser;
|
||||||
|
SharedPreferences settings;
|
||||||
|
SharedPreferences.Editor editor;
|
||||||
|
Server server;
|
||||||
|
Helpers helper;
|
||||||
|
Activity activity = this;
|
||||||
|
Intent imageData;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.homepage);
|
||||||
|
GetFromMain();
|
||||||
|
onLoad();
|
||||||
|
refreshHomepage();
|
||||||
|
changeTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetFromMain(){
|
||||||
|
id = Main.id;
|
||||||
|
settings = Main.settings;
|
||||||
|
editor = Main.editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddNewPost(View v){
|
||||||
|
Intent intent = new Intent(this, NewPost.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public void onLoad(){
|
||||||
|
postsList = findViewById(R.id.postsList);
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
loggedAs = findViewById(R.id.loggedAsText);
|
||||||
|
newPostBtn = findViewById(R.id.button);
|
||||||
|
refreshBtn = findViewById(R.id.refreshHomepage);
|
||||||
|
avatarUser = findViewById(R.id.avatarUser);
|
||||||
|
|
||||||
|
searchBar = findViewById(R.id.searchET);
|
||||||
|
navigationTab = findViewById(R.id.navigationTab);
|
||||||
|
searchView = findViewById(R.id.searchView);
|
||||||
|
homeView = findViewById(R.id.homeView);
|
||||||
|
menuView = findViewById(R.id.menuView);
|
||||||
|
|
||||||
|
searchResults = findViewById(R.id.searchResults);
|
||||||
|
|
||||||
|
ResultSet rs = server.query("username, nazwaWyswietlana, avatar", "users", "id = " + id);
|
||||||
|
try {
|
||||||
|
while(rs.next()) {
|
||||||
|
if(rs.getString(2).matches(""))
|
||||||
|
loggedAs.setText("Witaj,\n" + rs.getString(1));
|
||||||
|
else
|
||||||
|
loggedAs.setText("Witaj,\n" + rs.getString(2));
|
||||||
|
|
||||||
|
if(rs.getString(3) != null) {
|
||||||
|
if (!rs.getString(3).matches(""))
|
||||||
|
avatarUser.setImageBitmap(helper.convertToBitmap(rs.getString(3)));
|
||||||
|
else
|
||||||
|
avatarUser.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
} else
|
||||||
|
avatarUser.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMore(View v){
|
||||||
|
refreshHomepage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh(View v){
|
||||||
|
postsList.removeAllViewsInLayout();
|
||||||
|
posts = 0;
|
||||||
|
refreshHomepage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeAvatar(View v){
|
||||||
|
imgAdd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ActivityResultLauncher<String> requestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { imgAdd(); } else { Toast.makeText(this, "Nie możesz dodać zdjęcia do postu, ponieważ nie zezwoliłeś aplikacji na dostęp do plików.", Toast.LENGTH_LONG).show(); } });
|
||||||
|
|
||||||
|
@SuppressLint("IntentReset")
|
||||||
|
public void imgAdd(){
|
||||||
|
if(ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
|
pickIntent.setType("image/*");
|
||||||
|
startActivityForResult(pickIntent, 1);
|
||||||
|
} else {
|
||||||
|
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
public void refreshHomepage(){
|
||||||
|
/*String[][] publicTable = null;
|
||||||
|
new Thread(() -> {
|
||||||
|
int size = 0;
|
||||||
|
String[][] table = null;
|
||||||
|
try {
|
||||||
|
ResultSet rs1 = server.query("posts.id_post", "posts");
|
||||||
|
if (rs1 != null) {
|
||||||
|
rs1.last();
|
||||||
|
size = rs1.getRow();
|
||||||
|
}
|
||||||
|
int[] id_posts = new int[size];
|
||||||
|
|
||||||
|
ResultSet rs2 = server.query("posts.id_post", "posts");
|
||||||
|
while (rs2.next()) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
rs2.absolute(i + 1);
|
||||||
|
id_posts[i] = rs2.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table = new String[size][5];
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
String[][] finalTable = table;
|
||||||
|
int x = i;
|
||||||
|
new Thread(() ->{
|
||||||
|
GetEveryData data = new GetEveryData(id_posts[x], server);
|
||||||
|
finalTable[x][0] = data.giveData()[0];
|
||||||
|
finalTable[x][1] = data.giveData()[1];
|
||||||
|
finalTable[x][2] = data.giveData()[2];
|
||||||
|
finalTable[x][3] = data.giveData()[3];
|
||||||
|
finalTable[x][4] = data.giveData()[4];
|
||||||
|
}).start();
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
helper.GeneratePosts(
|
||||||
|
postsList,
|
||||||
|
id,
|
||||||
|
activity,
|
||||||
|
getBaseContext(),
|
||||||
|
"homepage",
|
||||||
|
finalTable[x][0],
|
||||||
|
finalTable[x][1],
|
||||||
|
finalTable[x][2],
|
||||||
|
finalTable[x][4],
|
||||||
|
finalTable[x][3]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
publicTable = table;
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();*/
|
||||||
|
ResultSet rs = server.query("posts.id_post, users.username, posts.tresc, posts.dataDodania, posts.tytul", "posts, users", "users.id = posts.id_autor", "ORDER BY id_post DESC LIMIT " + posts + ",5");
|
||||||
|
new AsyncTask<ResultSet, Void, String>(){
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(ResultSet... params){
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
try {
|
||||||
|
while (rs.next()) {
|
||||||
|
helper.GeneratePosts(
|
||||||
|
postsList,
|
||||||
|
id,
|
||||||
|
activity,
|
||||||
|
getBaseContext(),
|
||||||
|
"homepage",
|
||||||
|
params[0].getString(1),
|
||||||
|
params[0].getString(2),
|
||||||
|
params[0].getString(3),
|
||||||
|
params[0].getString(5),
|
||||||
|
params[0].getString(4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}.execute(rs);
|
||||||
|
|
||||||
|
Toast.makeText(this, "Pomyślnie zaktualizowano!", Toast.LENGTH_SHORT).show();
|
||||||
|
posts += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] con(String[] to){ return to;}
|
||||||
|
|
||||||
|
public void goToProfile(View v){
|
||||||
|
Intent intent = new Intent(this, Profile.class);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeTab(){
|
||||||
|
navigationTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(TabLayout.Tab tab) {
|
||||||
|
switch(tab.getPosition()){
|
||||||
|
case 0:
|
||||||
|
homeView.setVisibility(View.VISIBLE);
|
||||||
|
refreshBtn.setVisibility(View.VISIBLE);
|
||||||
|
newPostBtn.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
searchView.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
menuView.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(TabLayout.Tab tab) {
|
||||||
|
switch(tab.getPosition()){
|
||||||
|
case 0:
|
||||||
|
homeView.setVisibility(View.GONE);
|
||||||
|
refreshBtn.setVisibility(View.GONE);
|
||||||
|
newPostBtn.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
searchView.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
menuView.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logOff(View v){
|
||||||
|
editor.putInt("userID", 0);
|
||||||
|
editor.apply();
|
||||||
|
Intent intent = new Intent(this, Main.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editProfile(View v){
|
||||||
|
Intent intent = new Intent(this, EditProfile.class);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editDescription(View v){
|
||||||
|
EditText descriptionText = new EditText(this);
|
||||||
|
TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
params.setMargins(4,4,4,4);
|
||||||
|
descriptionText.setLayoutParams(params);
|
||||||
|
descriptionText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(200)});
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("opis", "users", "id = " + id);
|
||||||
|
|
||||||
|
while(rs.next()){
|
||||||
|
descriptionText.setText(rs.getString(1));
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
alert.setTitle("Twój opis");
|
||||||
|
alert.setView(descriptionText);
|
||||||
|
|
||||||
|
alert.setPositiveButton("Zapisz", (dialogInterface, i) -> {
|
||||||
|
server.update("users", "opis = '" + descriptionText.getText().toString() + "'", "id = " + id);
|
||||||
|
Toast.makeText(alert.getContext(), "Opis został zmieniony", Toast.LENGTH_SHORT).show();
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.setNegativeButton("Anuluj", (dialogInterface, i) -> {
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void search(View v){
|
||||||
|
searchResults.removeAllViewsInLayout();
|
||||||
|
findInAll(searchBar.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void findInAll(String phrase){
|
||||||
|
try {
|
||||||
|
// Uzytkownicy
|
||||||
|
ResultSet usersRS = server.query("username, opis, nazwaWyswietlana, zweryfikowany, avatar, id", "users", "username LIKE '%" + phrase + "%' OR nazwaWyswietlana LIKE '%" + phrase + "%' OR opis LIKE '%" + phrase + "%' LIMIT 3");
|
||||||
|
if(usersRS.isBeforeFirst()){
|
||||||
|
TextView textOne = new TextView(searchResults.getContext());
|
||||||
|
textOne.setId(View.generateViewId());
|
||||||
|
LinearLayout.LayoutParams textOneParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
textOne.setPadding(8, 8, 8, 8);
|
||||||
|
textOne.setLayoutParams(textOneParams);
|
||||||
|
textOne.setTextAppearance(R.style.TextAppearance_AppCompat_Medium);
|
||||||
|
textOne.setText("Użytkownicy");
|
||||||
|
searchResults.addView(textOne);
|
||||||
|
|
||||||
|
while (usersRS.next()) {
|
||||||
|
int id_user = usersRS.getInt(6);
|
||||||
|
|
||||||
|
TableRow userRow = new TableRow(searchResults.getContext());
|
||||||
|
userRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
userRow.setId(View.generateViewId());
|
||||||
|
userRow.setPadding(8,8,8,8);
|
||||||
|
|
||||||
|
ImageView avatarUser = new ImageView(userRow.getContext());
|
||||||
|
avatarUser.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams avatarParams = new TableRow.LayoutParams((int) getResources().getDisplayMetrics().density * 64, (int) getResources().getDisplayMetrics().density * 64);
|
||||||
|
avatarParams.setMargins(8, 8, 4, 8);
|
||||||
|
avatarUser.setLayoutParams(avatarParams);
|
||||||
|
avatarUser.setAdjustViewBounds(true);
|
||||||
|
avatarUser.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||||
|
|
||||||
|
if (usersRS.getString(5) != null) {
|
||||||
|
avatarUser.setImageBitmap(helper.convertToBitmap(usersRS.getString(5)));
|
||||||
|
} else {
|
||||||
|
avatarUser.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
}
|
||||||
|
|
||||||
|
avatarUser.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, Profile.class);
|
||||||
|
intent.putExtra("id_user", id_user);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
userRow.addView(avatarUser);
|
||||||
|
|
||||||
|
LinearLayout otherData = new LinearLayout(userRow.getContext());
|
||||||
|
otherData.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
otherData.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
otherData.setId(View.generateViewId());
|
||||||
|
|
||||||
|
TableRow usernameRow = new TableRow(otherData.getContext());
|
||||||
|
usernameRow.setId(View.generateViewId());
|
||||||
|
usernameRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
if (usersRS.getBoolean(4)) {
|
||||||
|
ImageView verifiedIcon = new ImageView(usernameRow.getContext());
|
||||||
|
verifiedIcon.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams verifiedParam = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT);
|
||||||
|
verifiedParam.setMargins(8, 8, 4, 4);
|
||||||
|
verifiedIcon.setLayoutParams(verifiedParam);
|
||||||
|
verifiedIcon.setImageIcon(Icon.createWithResource(this, R.drawable.verified_icon));
|
||||||
|
usernameRow.addView(verifiedIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView username = new TextView(usernameRow.getContext());
|
||||||
|
username.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams usernameParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
usernameParams.setMargins(4, 8, 8, 4);
|
||||||
|
username.setLayoutParams(usernameParams);
|
||||||
|
username.setText(usersRS.getString(1));
|
||||||
|
username.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, Profile.class);
|
||||||
|
intent.putExtra("id_user", id_user);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView description = new TextView(otherData.getContext());
|
||||||
|
description.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams descriptionParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
descriptionParams.setMargins(8, 4, 8, 8);
|
||||||
|
description.setLayoutParams(descriptionParams);
|
||||||
|
description.setText(usersRS.getString(2));
|
||||||
|
description.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, Profile.class);
|
||||||
|
intent.putExtra("id_user", id_user);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
usernameRow.addView(username);
|
||||||
|
otherData.addView(usernameRow);
|
||||||
|
otherData.addView(description);
|
||||||
|
userRow.addView(otherData);
|
||||||
|
|
||||||
|
searchResults.addView(userRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postManagement(View v) {
|
||||||
|
Intent intent = new Intent(this, PostsManagement.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void commentManagement(View v){
|
||||||
|
Intent intent = new Intent(this, CommentsManagement.class);
|
||||||
|
intent.putExtra("user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == 1 && resultCode == RESULT_OK) {
|
||||||
|
Bitmap bitmap = null;
|
||||||
|
if(data != null){
|
||||||
|
try{
|
||||||
|
imageData = data;
|
||||||
|
bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), imageData.getData());
|
||||||
|
Toast.makeText(this, helper.getThatPath(data.getData(), this), Toast.LENGTH_SHORT).show();
|
||||||
|
server.update("users", "avatar = '" + helper.convertToBase64(imageData, this) + "'", "id = " + id);
|
||||||
|
} catch (IOException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avatarUser.setImageBitmap(bitmap);
|
||||||
|
Toast.makeText(this, "Zmieniono", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.StrictMode;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Switch;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Main extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static int id;
|
||||||
|
boolean automaticLogIn = false;
|
||||||
|
|
||||||
|
EditText usernameText;
|
||||||
|
EditText passwordText;
|
||||||
|
Switch showPassword;
|
||||||
|
public static Server server;
|
||||||
|
|
||||||
|
public static SharedPreferences settings;
|
||||||
|
public static SharedPreferences.Editor editor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
onLoad();
|
||||||
|
passwordText.setOnEditorActionListener((v, actionId, event) -> {
|
||||||
|
if(actionId == EditorInfo.IME_ACTION_GO){
|
||||||
|
if(!usernameText.getText().toString().matches("") && !passwordText.getText().toString().matches(""))
|
||||||
|
LogIn();
|
||||||
|
else
|
||||||
|
Toast.makeText(this, "Nie możesz się zalogować bez podania danych do logowania!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
showPassword.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||||
|
if(b)
|
||||||
|
passwordText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||||||
|
else {
|
||||||
|
passwordText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad(){
|
||||||
|
setObjects();
|
||||||
|
policySet();
|
||||||
|
server = new Server();
|
||||||
|
showPassword = findViewById(R.id.showPassword);
|
||||||
|
|
||||||
|
settings = getApplicationContext().getSharedPreferences("userID", MODE_PRIVATE);
|
||||||
|
editor = settings.edit();
|
||||||
|
|
||||||
|
if(settings.getInt("userID", MODE_PRIVATE) == 0) {
|
||||||
|
automaticLogIn = false;
|
||||||
|
}else{
|
||||||
|
automaticLogIn = true;
|
||||||
|
LogIn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed(){
|
||||||
|
server.close();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setObjects(){
|
||||||
|
usernameText = findViewById(R.id.usernameBar);
|
||||||
|
passwordText = findViewById(R.id.passwordBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wymagane, aby mógł się połączyć z siecią
|
||||||
|
public void policySet(){
|
||||||
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddToTable(View v){
|
||||||
|
Intent intent = new Intent(this, Registration.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogInBtn(View v){
|
||||||
|
if(!usernameText.getText().toString().matches("") && !passwordText.getText().toString().matches(""))
|
||||||
|
LogIn();
|
||||||
|
else
|
||||||
|
Toast.makeText(this, "Nie możesz się zalogować bez podania danych do logowania!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogIn(){
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
DialogInterface.OnClickListener dialogClickListener;
|
||||||
|
try{
|
||||||
|
if(!automaticLogIn){
|
||||||
|
ResultSet rs = server.query("id, username, nazwaWyswietlana", "users", "username = '" + usernameText.getText() + "' OR numerTelefonu = '" + usernameText.getText() + "' OR email = '" + usernameText.getText() + "' AND password = PASSWORD('" + passwordText.getText() + "')");
|
||||||
|
|
||||||
|
if(rs.isBeforeFirst()){
|
||||||
|
while (rs.next()) {
|
||||||
|
id = rs.getInt(1);
|
||||||
|
String username = rs.getString(2);
|
||||||
|
String displayname = rs.getString(3);
|
||||||
|
dialogClickListener = (dialogInterface, i) -> {
|
||||||
|
switch (i) {
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
editor.putInt("userID", id);
|
||||||
|
editor.apply();
|
||||||
|
TheThirdLogIn(username, displayname);
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
TheThirdLogIn(username, displayname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
builder.setMessage("Czy chcesz zachować zalogowane konto na urządzeniu?").setPositiveButton("Tak", dialogClickListener).setNegativeButton("Nie", dialogClickListener).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Nie poprawne dane logowania", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
id = settings.getInt("userID", 0);
|
||||||
|
ResultSet rs = server.query("username, nazwaWyswietlana", "users", "id = " + id);
|
||||||
|
|
||||||
|
while(rs.next()){
|
||||||
|
TheThirdLogIn(rs.getString(1), rs.getString(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(SQLException ex){
|
||||||
|
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GoToHomepage(){
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TheThirdLogIn(String username, String displayname){
|
||||||
|
if (displayname == null)
|
||||||
|
Toast.makeText(Main.this, "Witaj ponownie, " + username + "!", Toast.LENGTH_LONG).show();
|
||||||
|
else
|
||||||
|
Toast.makeText(Main.this, "Witaj ponownie, " + displayname + "!", Toast.LENGTH_LONG).show();
|
||||||
|
GoToHomepage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
|
||||||
|
public class NewPost extends AppCompatActivity {
|
||||||
|
|
||||||
|
static int id;
|
||||||
|
Server server;
|
||||||
|
Helpers helper;
|
||||||
|
EditText text, title;
|
||||||
|
CheckBox nsfwTag;
|
||||||
|
ImageView imageToPost;
|
||||||
|
Intent imageData;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_new_post);
|
||||||
|
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLoad(){
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
|
||||||
|
id = Homepage.id;
|
||||||
|
text = findViewById(R.id.postTextBox);
|
||||||
|
title = findViewById(R.id.titleBox);
|
||||||
|
imageToPost = findViewById(R.id.imageToPost);
|
||||||
|
nsfwTag = findViewById(R.id.nsfwTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPost(View v){
|
||||||
|
if(!title.getText().toString().matches("")) {
|
||||||
|
String date = helper.GetDate();
|
||||||
|
String nsfw = "";
|
||||||
|
|
||||||
|
if (nsfwTag.isChecked())
|
||||||
|
nsfw = "1";
|
||||||
|
else
|
||||||
|
nsfw = "0";
|
||||||
|
|
||||||
|
try {
|
||||||
|
int id_post = 0;
|
||||||
|
if (imageData != null) {
|
||||||
|
server.insert("posts", "id_autor, dataDodania, tytul, tresc, typPosta, nsfw", id + ", NOW(), \"" + title.getText() + "\", \"" + text.getText() + "\", 1, " + nsfw);
|
||||||
|
ResultSet rsNew = server.query("id_post", "posts", "id_autor = '" + id + "' AND tytul = '" + title.getText() + "' AND tresc = '" + text.getText() + "' AND typPosta = '1';");
|
||||||
|
while (rsNew.next()) {
|
||||||
|
id_post = rsNew.getInt(1);
|
||||||
|
}
|
||||||
|
uploadImage(id, id_post, date, imageData);
|
||||||
|
} else
|
||||||
|
server.insert("posts", "id_autor, dataDodania, tytul, tresc, typPosta, nsfw", id + ", \"" + date + "\", \"" + title.getText() + "\", \"" + text.getText() + "\", 0, " + nsfw);
|
||||||
|
|
||||||
|
Toast.makeText(this, "Post został utworzony", Toast.LENGTH_LONG).show();
|
||||||
|
Intent intent = new Intent(this, ThePost.class);
|
||||||
|
intent.putExtra("id_post", id_post);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
intent.putExtra("from", "homepage");
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Post musi zawierać tytuł!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
public void addImage(View v){
|
||||||
|
imgAdd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ActivityResultLauncher<String> requestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { imgAdd(); } else { Toast.makeText(this, "Nie możesz dodać zdjęcia do postu, ponieważ nie zezwoliłeś aplikacji na dostęp do plików.", Toast.LENGTH_LONG).show(); } });
|
||||||
|
|
||||||
|
@SuppressLint("IntentReset")
|
||||||
|
public void imgAdd(){
|
||||||
|
if(ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
|
pickIntent.setType("image/*");
|
||||||
|
|
||||||
|
startActivityForResult(pickIntent, 1);
|
||||||
|
} else {
|
||||||
|
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (requestCode == 1 && resultCode == RESULT_OK) {
|
||||||
|
Bitmap bitmap = null;
|
||||||
|
if(data != null){
|
||||||
|
try{
|
||||||
|
imageData = data;
|
||||||
|
bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), imageData.getData());
|
||||||
|
Toast.makeText(this, helper.getThatPath(data.getData(), this), Toast.LENGTH_SHORT).show();
|
||||||
|
} catch (IOException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageToPost.setImageBitmap(bitmap);
|
||||||
|
Toast.makeText(this, "Dodałem się", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void uploadImage(int id_autor, int id_post, String dataDodania, Intent data) {
|
||||||
|
server.insert("posts_pictures", "NULL, '" + id_autor + "', '" + id_post + "', '" + helper.convertToBase64(data, this) + "', '" + dataDodania + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class PostsManagement extends AppCompatActivity {
|
||||||
|
|
||||||
|
LinearLayout postsList;
|
||||||
|
Server server;
|
||||||
|
public static int id;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_posts_management);
|
||||||
|
server = new Server();
|
||||||
|
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLoad(){
|
||||||
|
postsList = findViewById(R.id.postList);
|
||||||
|
id = Homepage.id;
|
||||||
|
refreshPosts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshPosts(){
|
||||||
|
ResultSet res = server.query("id_post, tresc, tytul, dataDodania", "posts", "id_autor = " + id, "ORDER BY id_post DESC");
|
||||||
|
try{
|
||||||
|
while(res.next()){
|
||||||
|
showPosts(
|
||||||
|
res.getInt(1),
|
||||||
|
res.getString(2),
|
||||||
|
res.getString(3),
|
||||||
|
res.getString(4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint({"SetTextI18n", "ResourceAsColor"})
|
||||||
|
public void showPosts(int id_post, String tresc, String title, String dataUtworzenia){
|
||||||
|
LinearLayout post = new LinearLayout(postsList.getContext());
|
||||||
|
LinearLayout.LayoutParams commentParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
commentParams.setMargins(0,4,8,4);
|
||||||
|
post.setLayoutParams(commentParams);
|
||||||
|
post.setId(View.generateViewId());
|
||||||
|
post.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
|
||||||
|
LinearLayout buttonGroup = new LinearLayout(post.getContext());
|
||||||
|
LinearLayout.LayoutParams btnGroupParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
buttonGroup.setLayoutParams(btnGroupParams);
|
||||||
|
buttonGroup.setId(View.generateViewId());
|
||||||
|
buttonGroup.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
buttonGroup.setGravity(Gravity.CENTER);
|
||||||
|
|
||||||
|
LinearLayout postContent = new LinearLayout(post.getContext());
|
||||||
|
LinearLayout.LayoutParams commentsParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
postContent.setLayoutParams(commentsParams);
|
||||||
|
postContent.setId(View.generateViewId());
|
||||||
|
postContent.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
|
||||||
|
ContextThemeWrapper theme = new ContextThemeWrapper(buttonGroup.getContext(), R.style.Widget_MaterialComponents_Button);
|
||||||
|
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
buttonParams.setMargins(8,2,8,2);
|
||||||
|
|
||||||
|
Button editButton = new Button(theme);
|
||||||
|
editButton.setLayoutParams(buttonParams);
|
||||||
|
editButton.setId(View.generateViewId());
|
||||||
|
editButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.description_icon, 0,0,0);
|
||||||
|
editButton.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, EditPost.class);
|
||||||
|
intent.putExtra("post", id_post);
|
||||||
|
intent.putExtra("user", id);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
Button deleteButton = new Button(theme);
|
||||||
|
deleteButton.setLayoutParams(buttonParams);
|
||||||
|
deleteButton.setId(View.generateViewId());
|
||||||
|
deleteButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.delete_icon,0,0,0);
|
||||||
|
deleteButton.setOnClickListener(view -> {
|
||||||
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
|
DialogInterface.OnClickListener alertDialog = (dialog, which) -> {
|
||||||
|
switch (which) {
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
server.delete("comments", "id_post = " + id_post);
|
||||||
|
server.delete("posts_likes", "id_post = " + id_post);
|
||||||
|
server.delete("posts_pictures", "id_post = " + id_post);
|
||||||
|
server.delete("posts", "id_post = " + id_post);
|
||||||
|
Toast.makeText(this, "Post został usunięty", Toast.LENGTH_SHORT).show();
|
||||||
|
postsList.removeAllViewsInLayout();
|
||||||
|
refreshPosts();
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
alert.setMessage("Czy na pewno chcesz usunąć ten post?").setPositiveButton("Tak", alertDialog).setNegativeButton("Nie", alertDialog).show();
|
||||||
|
});
|
||||||
|
|
||||||
|
Button postButton = new Button(theme);
|
||||||
|
postButton.setLayoutParams(buttonParams);
|
||||||
|
postButton.setId(View.generateViewId());
|
||||||
|
postButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.gotopost_icon,0,0,0);
|
||||||
|
postButton.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, ThePost.class);
|
||||||
|
intent.putExtra("id_user", id);
|
||||||
|
intent.putExtra("id_post", id_post);
|
||||||
|
intent.putExtra("from", "edit");
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView postTitle = new TextView(postContent.getContext());
|
||||||
|
postTitle.setId(View.generateViewId());
|
||||||
|
postTitle.setText(title);
|
||||||
|
|
||||||
|
TextView postText = new TextView(postContent.getContext());
|
||||||
|
postText.setId(View.generateViewId());
|
||||||
|
postText.setTextAppearance(R.style.TextAppearance_AppCompat_Medium);
|
||||||
|
postText.setText(tresc);
|
||||||
|
|
||||||
|
TextView addedText = new TextView(postContent.getContext());
|
||||||
|
addedText.setId(View.generateViewId());
|
||||||
|
addedText.setTextAppearance(R.style.TextAppearance_AppCompat_Body2);
|
||||||
|
addedText.setText(dataUtworzenia);
|
||||||
|
|
||||||
|
View divider = new View(postsList.getContext());
|
||||||
|
TableRow.LayoutParams dividerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) getResources().getDisplayMetrics().density);
|
||||||
|
dividerParams.setMargins(32, 24, 32, 24);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(getColor(R.color.gray_400));
|
||||||
|
|
||||||
|
buttonGroup.addView(editButton);
|
||||||
|
buttonGroup.addView(postButton);
|
||||||
|
buttonGroup.addView(deleteButton);
|
||||||
|
postContent.addView(postTitle);
|
||||||
|
postContent.addView(postText);
|
||||||
|
postContent.addView(addedText);
|
||||||
|
|
||||||
|
post.addView(buttonGroup);
|
||||||
|
post.addView(postContent);
|
||||||
|
|
||||||
|
postsList.addView(post);
|
||||||
|
postsList.addView(divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit(View v){
|
||||||
|
Intent homepage = new Intent(this, Homepage.class);
|
||||||
|
startActivity(homepage);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed(){
|
||||||
|
Intent homepage = new Intent(this, Homepage.class);
|
||||||
|
startActivity(homepage);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,354 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
public class Profile extends AppCompatActivity {
|
||||||
|
|
||||||
|
int id;
|
||||||
|
int id_user;
|
||||||
|
Server server;
|
||||||
|
Helpers helper;
|
||||||
|
TextView nameText, usernameText, observedByText, descriptionText;
|
||||||
|
ImageView verifiedIcon, avatarImage;
|
||||||
|
Button observationBtn;
|
||||||
|
TabLayout navigationTab;
|
||||||
|
|
||||||
|
LinearLayout posts, comments;
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_profile);
|
||||||
|
onLoad();
|
||||||
|
changeTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLoad(){
|
||||||
|
nameText = findViewById(R.id.nameText);
|
||||||
|
usernameText = findViewById(R.id.usernameText);
|
||||||
|
observedByText = findViewById(R.id.observedByText);
|
||||||
|
verifiedIcon = findViewById(R.id.verifiedIcon);
|
||||||
|
observationBtn = findViewById(R.id.observationBtn);
|
||||||
|
navigationTab = findViewById(R.id.navigationTab);
|
||||||
|
descriptionText = findViewById(R.id.descriptionText);
|
||||||
|
avatarImage = findViewById(R.id.avatarImage);
|
||||||
|
|
||||||
|
comments = findViewById(R.id.comments);
|
||||||
|
posts = findViewById(R.id.posts);
|
||||||
|
|
||||||
|
id = Homepage.id;
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
|
||||||
|
Bundle fromSomewhere = getIntent().getExtras();
|
||||||
|
id_user = fromSomewhere.getInt("id_user");
|
||||||
|
|
||||||
|
giveMeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quitTheProfile(View v){
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed(){
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeTab(){
|
||||||
|
navigationTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(TabLayout.Tab tab) {
|
||||||
|
switch(tab.getPosition()){
|
||||||
|
case 0:
|
||||||
|
posts.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
comments.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(TabLayout.Tab tab) {
|
||||||
|
switch(tab.getPosition()){
|
||||||
|
case 0:
|
||||||
|
posts.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
comments.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void giveMeAll(){
|
||||||
|
try{
|
||||||
|
ResultSet rsComments = server.query("DISTINCT users.username, comments.tresc, comments.dataUtworzenia, comments.id_post, posts.id_autor, comments.id_post", "comments, users, posts", "comments.id_author = " + id_user + " AND users.id = comments.id_author AND comments.id_post = posts.id_post", "ORDER BY comments.dataUtworzenia DESC");
|
||||||
|
while(rsComments.next()) {
|
||||||
|
String username = rsComments.getString(1);
|
||||||
|
String tresc = rsComments.getString(2);
|
||||||
|
String dataUtworzenia = rsComments.getString(3);
|
||||||
|
int id_post = rsComments.getInt(4);
|
||||||
|
ResultSet rsAuthor = server.query("users.username", "users", "users.id = " + rsComments.getInt(5));
|
||||||
|
while(rsAuthor.next())
|
||||||
|
showComments(
|
||||||
|
id_post,
|
||||||
|
username,
|
||||||
|
tresc,
|
||||||
|
dataUtworzenia,
|
||||||
|
rsAuthor.getString(1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ResultSet rsPost = server.query("posts.id_post, users.username, posts.tresc, posts.dataDodania", "posts, users", "users.id = posts.id_autor AND posts.id_autor = " + id_user, "ORDER BY id_post DESC");
|
||||||
|
|
||||||
|
while(rsPost.next())
|
||||||
|
showPosts(
|
||||||
|
Integer.parseInt(rsPost.getString(1)),
|
||||||
|
rsPost.getString(2),
|
||||||
|
rsPost.getString(3),
|
||||||
|
rsPost.getString(4)
|
||||||
|
);
|
||||||
|
|
||||||
|
ResultSet rsUser = server.query("username, nazwaWyswietlana, zweryfikowany, opis, avatar", "users", "id = " + id_user);
|
||||||
|
|
||||||
|
while(rsUser.next()){
|
||||||
|
usernameText.setText(rsUser.getString(1));
|
||||||
|
nameText.setText(rsUser.getString(2));
|
||||||
|
descriptionText.setText(rsUser.getString(4));
|
||||||
|
if(rsUser.getInt(3) == 1)
|
||||||
|
verifiedIcon.setImageIcon(Icon.createWithResource(this, R.drawable.verified_icon));
|
||||||
|
else
|
||||||
|
verifiedIcon.setImageIcon(Icon.createWithResource(this, R.drawable.normaluser_icon));
|
||||||
|
|
||||||
|
if(rsUser.getString(5) != null) {
|
||||||
|
if(!rsUser.getString(5).matches(""))
|
||||||
|
avatarImage.setImageBitmap(helper.convertToBitmap(rsUser.getString(5)));
|
||||||
|
else
|
||||||
|
avatarImage.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
}else
|
||||||
|
avatarImage.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet rsFollowers = server.query("COUNT(*)", "users_observations", "id_observedProfile = " + id_user);
|
||||||
|
while(rsFollowers.next())
|
||||||
|
observedByText.setText(rsFollowers.getInt(1) + " obserwujących");
|
||||||
|
|
||||||
|
if(id_user == id)
|
||||||
|
observationBtn.setVisibility(View.GONE);
|
||||||
|
else {
|
||||||
|
ResultSet rsObs = server.query("id_observation", "users_observations", "id_observedProfile = " + id_user + " AND id_observedBy = " + id);
|
||||||
|
|
||||||
|
if (rsObs.next()){
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observed_icon, 0,0,0);
|
||||||
|
} else
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observe_icon, 0,0,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void observation(View v){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id_observation", "users_observations", "id_observedProfile = " + id_user + " AND id_observedBy = " + id);
|
||||||
|
|
||||||
|
if(!rs.isBeforeFirst()){
|
||||||
|
server.insert("users_observations", "NULL, " + id_user + ", " + id_user + ", '" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "'");
|
||||||
|
Toast.makeText(this, "Zaobserwowano profil", Toast.LENGTH_SHORT).show();
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observed_icon, 0,0,0);
|
||||||
|
|
||||||
|
ResultSet rsFollowers = server.query("COUNT(*)", "users_observations", "id_observedProfile = " + id_user);
|
||||||
|
while(rsFollowers.next())
|
||||||
|
observedByText.setText(rsFollowers.getInt(1) + " obserwujących");
|
||||||
|
} else {
|
||||||
|
server.delete("users_observations", "id_observedProfile = " + id_user + " AND id_observedBy = " + id);
|
||||||
|
Toast.makeText(this, "Już nie obserwujesz tego profilu", Toast.LENGTH_SHORT).show();
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observe_icon, 0,0,0);
|
||||||
|
|
||||||
|
ResultSet rsFollowers = server.query("COUNT(*)", "users_observations", "id_observedProfile = " + id_user);
|
||||||
|
while(rsFollowers.next())
|
||||||
|
observedByText.setText(rsFollowers.getInt(1) + " obserwujących");
|
||||||
|
}
|
||||||
|
} catch(SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint({"SetTextI18n", "ResourceAsColor"})
|
||||||
|
public void showPosts(int id_post, String autor, String text, String datetime){
|
||||||
|
TableLayout table = new TableLayout(posts.getContext());
|
||||||
|
TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
|
||||||
|
table.setId(View.generateViewId());
|
||||||
|
table.setLayoutParams(tableParams);
|
||||||
|
|
||||||
|
TableRow authorRow = new TableRow(table.getContext());
|
||||||
|
authorRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
TextView authorLabel = new TextView(authorRow.getContext());
|
||||||
|
authorLabel.setPadding(16,16,16,16);
|
||||||
|
authorLabel.setText(autor + " \nDodano: " + datetime);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
TableRow textRow = new TableRow(table.getContext());
|
||||||
|
textRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
TextView textLabel = new TextView(textRow.getContext());
|
||||||
|
textLabel.setPadding(16,16,16,16);
|
||||||
|
textLabel.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
textLabel.setMaxLines(5);
|
||||||
|
textLabel.setTextSize(20f);
|
||||||
|
textLabel.setText(text);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
|
||||||
|
TableRow likesRow = new TableRow(table.getContext());
|
||||||
|
likesRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
|
Button goToPost = new Button(likesRow.getContext());
|
||||||
|
goToPost.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams redirectParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 96, 1f);
|
||||||
|
redirectParams.setMargins(16, 4, 16, 4);
|
||||||
|
goToPost.setBackgroundColor(ContextCompat.getColor(this, R.color.purple_500));
|
||||||
|
goToPost.setTextColor(Color.WHITE);
|
||||||
|
goToPost.setLayoutParams(redirectParams);
|
||||||
|
goToPost.setText("Pokaż cały post");
|
||||||
|
goToPost.setOnClickListener(
|
||||||
|
view -> {
|
||||||
|
Intent thePostIntent = new Intent(this, ThePost.class);
|
||||||
|
thePostIntent.putExtra("id_user", id);
|
||||||
|
thePostIntent.putExtra("id_post", id_post);
|
||||||
|
startActivity(thePostIntent);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
View divider = new View(posts.getContext());
|
||||||
|
TableRow.LayoutParams dividerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) getResources().getDisplayMetrics().density);
|
||||||
|
dividerParams.setMargins(32, 32, 32, 32);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(ContextCompat.getColor(this, R.color.gray_400));
|
||||||
|
|
||||||
|
likesRow.addView(goToPost);
|
||||||
|
textRow.addView(textLabel);
|
||||||
|
authorRow.addView(authorLabel);
|
||||||
|
|
||||||
|
table.addView(authorRow);
|
||||||
|
table.addView(textRow);
|
||||||
|
table.addView(likesRow);
|
||||||
|
posts.addView(table);
|
||||||
|
posts.addView(divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void showComments(int id_post, String autor, String tresc, String dataUtworzenia, String autorPosta){
|
||||||
|
LinearLayout comment = new LinearLayout(comments.getContext());
|
||||||
|
LinearLayout.LayoutParams linParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
comment.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
comment.setId(View.generateViewId());
|
||||||
|
comment.setLayoutParams(linParams);
|
||||||
|
|
||||||
|
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
|
||||||
|
TableRow authorRow = new TableRow(comment.getContext());
|
||||||
|
authorRow.setId(View.generateViewId());
|
||||||
|
authorRow.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView authorText = new TextView(authorRow.getContext());
|
||||||
|
authorText.setId(View.generateViewId());
|
||||||
|
authorText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
authorText.setPadding(16, 16, 16, 4);
|
||||||
|
authorText.setText(autor + " odpowiedział " + autorPosta);
|
||||||
|
|
||||||
|
TableRow content = new TableRow(comment.getContext());
|
||||||
|
content.setId(View.generateViewId());
|
||||||
|
content.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView contentText = new TextView(authorRow.getContext());
|
||||||
|
contentText.setId(View.generateViewId());
|
||||||
|
contentText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
contentText.setPadding(16, 4, 16, 4);
|
||||||
|
contentText.setAutoLinkMask(Linkify.ALL);
|
||||||
|
contentText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
contentText.setText(tresc);
|
||||||
|
|
||||||
|
TableRow added = new TableRow(comment.getContext());
|
||||||
|
added.setId(View.generateViewId());
|
||||||
|
added.setLayoutParams(rowParams);
|
||||||
|
|
||||||
|
TextView addedText = new TextView(authorRow.getContext());
|
||||||
|
addedText.setId(View.generateViewId());
|
||||||
|
addedText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
||||||
|
addedText.setPadding(16, 4, 16, 16);
|
||||||
|
addedText.setText("Dodano " + dataUtworzenia);
|
||||||
|
|
||||||
|
Button goToPost = new Button(comments.getContext());
|
||||||
|
goToPost.setId(View.generateViewId());
|
||||||
|
TableRow.LayoutParams redirectParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 96, 1f);
|
||||||
|
redirectParams.setMargins(16, 4, 16, 4);
|
||||||
|
goToPost.setBackgroundColor(ContextCompat.getColor(this, R.color.purple_500));
|
||||||
|
goToPost.setTextColor(Color.WHITE);
|
||||||
|
goToPost.setLayoutParams(redirectParams);
|
||||||
|
goToPost.setText("Pokaż cały post");
|
||||||
|
goToPost.setOnClickListener(
|
||||||
|
view -> {
|
||||||
|
Intent thePostIntent = new Intent(this, ThePost.class);
|
||||||
|
thePostIntent.putExtra("id_user", id);
|
||||||
|
thePostIntent.putExtra("id_post", id_post);
|
||||||
|
startActivity(thePostIntent);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
View divider = new View(comments.getContext());
|
||||||
|
TableRow.LayoutParams dividerParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, (int) getResources().getDisplayMetrics().density);
|
||||||
|
dividerParams.setMargins(32, 32, 32, 32);
|
||||||
|
divider.setLayoutParams(dividerParams);
|
||||||
|
divider.setBackgroundColor(ContextCompat.getColor(this, R.color.gray_400));
|
||||||
|
|
||||||
|
authorRow.addView(authorText);
|
||||||
|
content.addView(contentText);
|
||||||
|
added.addView(addedText);
|
||||||
|
|
||||||
|
comment.addView(authorRow);
|
||||||
|
comment.addView(content);
|
||||||
|
comment.addView(added);
|
||||||
|
|
||||||
|
comments.addView(comment);
|
||||||
|
comments.addView(goToPost);
|
||||||
|
comments.addView(divider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.view.View;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
public class Registration extends AppCompatActivity {
|
||||||
|
|
||||||
|
EditText nicknameBox, passwordBox, rpPasswordBox, nameBox, emailBox, phoneBox;
|
||||||
|
RadioButton maleBox, femaleBox;
|
||||||
|
TextView passwordIdentityText, birthdateBox, tosLink;
|
||||||
|
CheckBox acceptToS;
|
||||||
|
Button registerBtn;
|
||||||
|
|
||||||
|
String[] firstPartMale = {"Ambitny", "Zabawny", "Kreatywny", "Śmierdzacy", "Stanowczy", "Lojalny", "Dziwny", "Przyzwoity", "Przemądrzały", "Optymistyczny", "Pesymistyczny", "Zwariowany", "Zmarnowany", "Towarzyski", "Szczery", "Latający", "Aktywny", "Bezużyteczny", "Nieśmieszny"};
|
||||||
|
String[] secondPartMale = {"Dinozaur", "Robot", "Odkurzacz", "Tygrys", "Nerd", "Gracz", "Przegryw", "Król", "Kujon", "Kierowca", "Drifter", "Aparaciarz", "Zgredek"};
|
||||||
|
String[] firstPartFemale = {"Ambitna", "Zabawna", "Kreatywna", "Śmierdzaca", "Stanowcza", "Lojalna", "Dziwna", "Przyzwoita", "Przemądrzała", "Optymistyczna", "Pesymistyczna", "Zwariowana", "Zmarnowana", "Towarzyska", "Szczera", "Latająca", "Aktywna", "Bezużyteczna", "Nieśmieszna"};
|
||||||
|
String[] secondPartFemale = {"Dinozaur", "Robot", "Tygrysica", "Nerdini", "Graczka", "Przegrywka", "Królowa", "Kujonka", "Kierowczyni", "Drifterka", "Aparatka", "Zgredka"};
|
||||||
|
|
||||||
|
DatePickerDialog.OnDateSetListener dateSetListener;
|
||||||
|
Server server;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_registration);
|
||||||
|
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void onLoad(){
|
||||||
|
nicknameBox = findViewById(R.id.usernameBar);
|
||||||
|
birthdateBox = findViewById(R.id.birthdateBox);
|
||||||
|
passwordBox = findViewById(R.id.passwordBox);
|
||||||
|
rpPasswordBox = findViewById(R.id.rpPasswordBox);
|
||||||
|
nameBox = findViewById(R.id.nameBox);
|
||||||
|
emailBox = findViewById(R.id.emailBox);
|
||||||
|
phoneBox = findViewById(R.id.phoneBox);
|
||||||
|
tosLink = findViewById(R.id.tosLink);
|
||||||
|
|
||||||
|
tosLink.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
|
server = new Server();
|
||||||
|
|
||||||
|
maleBox = findViewById(R.id.maleBtn);
|
||||||
|
femaleBox = findViewById(R.id.femaleBtn);
|
||||||
|
|
||||||
|
passwordIdentityText = findViewById(R.id.identityLogText);
|
||||||
|
registerBtn = findViewById(R.id.registerBtn);
|
||||||
|
|
||||||
|
acceptToS = findViewById(R.id.acceptToS);
|
||||||
|
|
||||||
|
dateSetListener = (datePicker, i, i1, i2) -> {
|
||||||
|
String year, month, day;
|
||||||
|
i1++;
|
||||||
|
month = (i1 < 10 ? "0" + i1 : Integer.toString(i1));
|
||||||
|
day = (i2 < 10 ? "0" + i2 : Integer.toString(i2));
|
||||||
|
year = Integer.toString(i);
|
||||||
|
|
||||||
|
birthdateBox.setText(year + "/" + month + "/" + day);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void birthdateEvent(View v){
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|
||||||
|
int year = cal.get(Calendar.YEAR);
|
||||||
|
int month = cal.get(Calendar.MONTH);
|
||||||
|
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
DatePickerDialog dialog = new DatePickerDialog(this, AlertDialog.THEME_HOLO_LIGHT, dateSetListener, year, month, day);
|
||||||
|
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void randomMeNickname(View v){
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder x = new StringBuilder();
|
||||||
|
|
||||||
|
if(maleBox.isChecked()) {
|
||||||
|
x.append(firstPartMale[random.nextInt(firstPartMale.length)]);
|
||||||
|
x.append(secondPartMale[random.nextInt(secondPartMale.length)]);
|
||||||
|
} else {
|
||||||
|
x.append(firstPartFemale[random.nextInt(firstPartFemale.length)]);
|
||||||
|
x.append(secondPartFemale[random.nextInt(secondPartFemale.length)]);
|
||||||
|
}
|
||||||
|
x.append(random.nextInt(999));
|
||||||
|
|
||||||
|
nicknameBox.setText(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerMe(View v){
|
||||||
|
int plec;
|
||||||
|
|
||||||
|
if(maleBox.isChecked())
|
||||||
|
plec = 1;
|
||||||
|
else
|
||||||
|
plec = 0;
|
||||||
|
|
||||||
|
Pattern p = Pattern.compile("[^A-Za-z0-9]", Pattern.CASE_INSENSITIVE);
|
||||||
|
Matcher m = p.matcher(nicknameBox.getText());
|
||||||
|
|
||||||
|
if(acceptToS.isChecked()) {
|
||||||
|
if(!m.find()) {
|
||||||
|
if (passwordBox.getText().toString().equals(rpPasswordBox.getText().toString())) {
|
||||||
|
if (!nicknameBox.getText().equals("") && !birthdateBox.getText().equals("")) {
|
||||||
|
if (nicknameBox.getText().length() > 3) {
|
||||||
|
try {
|
||||||
|
server.insert("users", "username, password, nazwaWyswietlana, email, numerTelefonu, dataUrodzenia, plec",
|
||||||
|
"'" + nicknameBox.getText() + "', PASSWORD('" + passwordBox.getText() + "'), '" + nameBox.getText() + "', '" + emailBox.getText() + "', '" + phoneBox.getText() + "', '" + birthdateBox.getText() + "', " + plec);
|
||||||
|
if (!nameBox.getText().equals("")) {
|
||||||
|
Toast.makeText(this, "Konto zostało utworzone. Witaj na pokładzie, " + nameBox.getText() + "!", Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Konto zostało utworzone. Witaj na pokładzie, " + nicknameBox.getText() + "!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet rs = server.query("id", "users", "username = '" + nicknameBox.getText() + "'");
|
||||||
|
while (rs.next()) {
|
||||||
|
Main.id = rs.getInt(1);
|
||||||
|
Intent intent = new Intent(this, Homepage.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
} else Toast.makeText(this, "Za krótka nazwa użytkownika! Minimalnie 4 znaki.", Toast.LENGTH_LONG).show();
|
||||||
|
} else Toast.makeText(this, "Nazwa użytkownika jest wymagana! Jeżeli nie masz pomysłu, to wygeneruj sobie.", Toast.LENGTH_LONG).show();
|
||||||
|
} else Toast.makeText(this, "Wpisane hasła nie są identyczne, for blyat sake!", Toast.LENGTH_LONG).show();
|
||||||
|
} else Toast.makeText(this, "Nazwa użytkownika nie może zawierać znaków specjalnych. Jedynie litery oraz cyfry zezwolone!", Toast.LENGTH_LONG).show();
|
||||||
|
} else Toast.makeText(this, "Aby korzystać z serwisu musisz zakceptować regulamin!", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelRegistration(View v){
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class Server {
|
||||||
|
String username = "";
|
||||||
|
String password = "";
|
||||||
|
String url = "jdbc:mysql://";
|
||||||
|
Connection conn;
|
||||||
|
|
||||||
|
public Connection connection(){
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
conn = DriverManager.getConnection(url, username, password);
|
||||||
|
} catch (SQLException | ClassNotFoundException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Statement stmt() {
|
||||||
|
Statement stmt = null;
|
||||||
|
try{ stmt = connection().createStatement(); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
return stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet query(String columns, String from, String type, String table, String joinOn, String where, String args) {
|
||||||
|
ResultSet res = null;
|
||||||
|
try {
|
||||||
|
res = stmt().executeQuery("SELECT " + columns + " FROM " + from + " " + type + " JOIN " + table + " ON " + joinOn + " WHERE " + where + " " + args + ";");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet query(String columns, String from, String type, String table, String joinOn, String where) {
|
||||||
|
ResultSet res = null;
|
||||||
|
try {
|
||||||
|
res = stmt().executeQuery("SELECT " + columns + " FROM " + from + " " + type + " JOIN " + table + " ON " + joinOn + " WHERE " + where + ";");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet query(String columns, String from, String where, String args) {
|
||||||
|
ResultSet res = null;
|
||||||
|
try {
|
||||||
|
res = stmt().executeQuery("SELECT " + columns + " FROM " + from + " WHERE " + where + " " + args + ";");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet query(String columns, String from, String where) {
|
||||||
|
ResultSet res = null;
|
||||||
|
try {
|
||||||
|
res = stmt().executeQuery("SELECT " + columns + " FROM " + from + " WHERE " + where + ";");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultSet query(String columns, String from) {
|
||||||
|
ResultSet res = null;
|
||||||
|
try {
|
||||||
|
res = stmt().executeQuery("SELECT " + columns + " FROM " + from + ";");
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(String table, String changes, String where) {
|
||||||
|
try {stmt().executeUpdate("UPDATE " + table + " SET " + changes + " WHERE " + where + ";"); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(String from, String where){
|
||||||
|
try { stmt().executeUpdate("DELETE FROM " + from + " WHERE " + where + ";"); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(String table, String columns, String values){
|
||||||
|
try {stmt().executeUpdate("INSERT INTO " + table + "(" + columns + ") VALUES(" + values + ");"); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(String table, String values){
|
||||||
|
try {stmt().executeUpdate("INSERT INTO " + table + " VALUES(" + values + ");"); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close(){
|
||||||
|
try{ connection().close(); } catch (SQLException ex) { ex.printStackTrace(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
package pl.krzysiek.simplesocial;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
public class ThePost extends AppCompatActivity {
|
||||||
|
|
||||||
|
int id_user;
|
||||||
|
int id_post;
|
||||||
|
|
||||||
|
int id_author;
|
||||||
|
String from;
|
||||||
|
|
||||||
|
ImageView postImage, avatarView;
|
||||||
|
Server server;
|
||||||
|
Helpers helper;
|
||||||
|
|
||||||
|
TextView author, createDate, contentOfPost, likes, title;
|
||||||
|
EditText commentBox;
|
||||||
|
Button likeBtn, observationBtn;
|
||||||
|
|
||||||
|
LinearLayout linearLayout;
|
||||||
|
LinearLayout comments;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.thepost);
|
||||||
|
onLoad();
|
||||||
|
updateThePost();
|
||||||
|
refreshComments();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onLoad(){
|
||||||
|
Bundle homepage = getIntent().getExtras();
|
||||||
|
id_user = homepage.getInt("id_user");
|
||||||
|
id_post = homepage.getInt("id_post");
|
||||||
|
from = homepage.getString("from");
|
||||||
|
server = new Server();
|
||||||
|
helper = new Helpers();
|
||||||
|
|
||||||
|
author = findViewById(R.id.userText);
|
||||||
|
createDate = findViewById(R.id.createDateText);
|
||||||
|
observationBtn = findViewById(R.id.observeBtn);
|
||||||
|
|
||||||
|
postImage = findViewById(R.id.postImage);
|
||||||
|
|
||||||
|
contentOfPost = findViewById(R.id.contentText);
|
||||||
|
contentOfPost.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
title = findViewById(R.id.titleText);
|
||||||
|
avatarView = findViewById(R.id.avatarView);
|
||||||
|
|
||||||
|
likes = findViewById(R.id.likesText);
|
||||||
|
likeBtn = findViewById(R.id.likeBtn);
|
||||||
|
commentBox = findViewById(R.id.commentBox);
|
||||||
|
comments = findViewById(R.id.comments);
|
||||||
|
linearLayout = findViewById(R.id.postLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void updateThePost(){
|
||||||
|
int typ = 0;
|
||||||
|
try{
|
||||||
|
ResultSet rsPost = server.query("users.username, posts.dataDodania, posts.tresc, posts.id_autor, posts.tytul, posts.typPosta, users.avatar", "posts, users", "posts.id_post = " + id_post + " AND users.id = posts.id_autor");
|
||||||
|
|
||||||
|
while(rsPost.next()){
|
||||||
|
author.setText(rsPost.getString(1));
|
||||||
|
createDate.setText("Dodano " + rsPost.getString(2));
|
||||||
|
contentOfPost.setText(rsPost.getString(3));
|
||||||
|
id_author = rsPost.getInt(4);
|
||||||
|
title.setText(rsPost.getString(5));
|
||||||
|
typ = rsPost.getInt(6);
|
||||||
|
|
||||||
|
if(rsPost.getString(7) != null) {
|
||||||
|
if(!rsPost.getString(7).matches(""))
|
||||||
|
avatarView.setImageBitmap(helper.convertToBitmap(rsPost.getString(7)));
|
||||||
|
else
|
||||||
|
avatarView.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
} else
|
||||||
|
avatarView.setImageIcon(Icon.createWithResource(this, R.drawable.default_avatar));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet rsLikes = server.query("COUNT(*)", "posts_likes", "id_post = " + id_post);
|
||||||
|
while(rsLikes.next()){
|
||||||
|
likes.setText(rsLikes.getString(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typ > 0){
|
||||||
|
ResultSet rsImage = server.query("picture", "posts_pictures", "id_post = " + id_post + " AND id_autor = " + id_author);
|
||||||
|
while(rsImage.next()) {
|
||||||
|
postImage.setImageBitmap(helper.convertToBitmap(rsImage.getString(1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(id_author == id_user)
|
||||||
|
observationBtn.setVisibility(View.GONE);
|
||||||
|
else {
|
||||||
|
ResultSet rsObs = server.query("id_observation", "users_observations", "id_observedProfile = " + id_author + " AND id_observedBy = " + id_user);
|
||||||
|
|
||||||
|
if(!rsObs.isBeforeFirst())
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observe_icon, 0,0,0);
|
||||||
|
else
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observed_icon, 0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet rs = server.query("id_like", "posts_likes", "id_post = " + id_post + " AND id_user = " + id_user + ";");
|
||||||
|
|
||||||
|
if(!rs.next())
|
||||||
|
likeBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.like_icon, 0, 0, 0);
|
||||||
|
else
|
||||||
|
likeBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.liked_icon, 0, 0, 0);
|
||||||
|
|
||||||
|
} catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goToProfile(View v){
|
||||||
|
Intent intent = new Intent(this, Profile.class);
|
||||||
|
intent.putExtra("id_user", id_author);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void giveAComment(View v){
|
||||||
|
if(!title.getText().toString().matches("")) {
|
||||||
|
server.insert("comments", "NULL, " + id_post + ", " + id_user + ", NOW(), '" + commentBox.getText() + "', 0");
|
||||||
|
commentBox.setText("");
|
||||||
|
refreshComments();
|
||||||
|
Toast.makeText(this, "Komentarz dodany!", Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Nie można dodawać pustych komentarzy", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshComments(){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("users.username, comments.tresc, comments.dataUtworzenia", "comments, users", "comments.id_post = " + id_post + " AND users.id = comments.id_author", "ORDER BY comments.dataUtworzenia DESC");
|
||||||
|
comments.removeAllViewsInLayout();
|
||||||
|
while(rs.next())
|
||||||
|
helper.GenerateComments(
|
||||||
|
comments,
|
||||||
|
rs.getString(1),
|
||||||
|
getBaseContext(),
|
||||||
|
rs.getString(2),
|
||||||
|
rs.getString(3),
|
||||||
|
author
|
||||||
|
);
|
||||||
|
Toast.makeText(this, "Pomyślnie zaktualizowano!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
catch (SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void giveALike(View v){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id_like", "posts_likes", "id_post = " + id_post + " AND id_user = " + id_user);
|
||||||
|
|
||||||
|
if(!rs.isBeforeFirst()){
|
||||||
|
server.insert("posts_likes", "NULL, " + id_post + ", " + id_user + ", '" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "'");
|
||||||
|
likeBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.liked_icon, 0, 0, 0);
|
||||||
|
} else {
|
||||||
|
server.delete("posts_likes", "id_post = " + id_post + " AND id_user = " + id_user + ";");
|
||||||
|
likeBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.like_icon, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet rsLikes = server.query("COUNT(*)", "posts_likes", "id_post = " + id_post);
|
||||||
|
while(rsLikes.next()){
|
||||||
|
likes.setText(rsLikes.getString(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void observation(View v){
|
||||||
|
try{
|
||||||
|
ResultSet rs = server.query("id_observation", "users_observations", "id_observedProfile = " + id_author + " AND id_observedBy = " + id_user);
|
||||||
|
|
||||||
|
if(!rs.isBeforeFirst()){
|
||||||
|
server.insert("users_observations", "NULL, " + id_author + ", " + id_user + ", '" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "'");
|
||||||
|
Toast.makeText(this, "Zaobserwowano profil", Toast.LENGTH_SHORT).show();
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observed_icon, 0,0,0);
|
||||||
|
} else {
|
||||||
|
server.delete("users_observations", "id_observedProfile = " + id_author + " AND id_observedBy = " + id_user);
|
||||||
|
Toast.makeText(this, "Już nie obserwujesz tego profilu", Toast.LENGTH_SHORT).show();
|
||||||
|
observationBtn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.observe_icon, 0,0,0);
|
||||||
|
}
|
||||||
|
} catch(SQLException ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exitPost(View v){
|
||||||
|
Intent parent = null;
|
||||||
|
switch (from) {
|
||||||
|
case "homepage":
|
||||||
|
parent = new Intent(this, Homepage.class);
|
||||||
|
break;
|
||||||
|
case "user":
|
||||||
|
parent = new Intent(this, Profile.class);
|
||||||
|
parent.putExtra("id_user", id_author);
|
||||||
|
break;
|
||||||
|
case "edit":
|
||||||
|
parent = new Intent(this, PostsManagement.class);
|
||||||
|
break;
|
||||||
|
case "comment":
|
||||||
|
parent = new Intent(this, CommentsManagement.class);
|
||||||
|
parent.putExtra("user", id_user);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
startActivity(parent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM19,11h-4v4h-2v-4L9,11L9,9h4L13,5h2v4h4v2z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM7.07,18.28c0.43,-0.9 3.05,-1.78 4.93,-1.78s4.51,0.88 4.93,1.78C15.57,19.36 13.86,20 12,20s-3.57,-0.64 -4.93,-1.72zM18.36,16.83c-1.43,-1.74 -4.9,-2.33 -6.36,-2.33s-4.93,0.59 -6.36,2.33C4.62,15.49 4,13.82 4,12c0,-4.41 3.59,-8 8,-8s8,3.59 8,8c0,1.82 -0.62,3.49 -1.64,4.83zM12,6c-1.94,0 -3.5,1.56 -3.5,3.5S10.06,13 12,13s3.5,-1.56 3.5,-3.5S13.94,6 12,6zM12,11c-0.83,0 -1.5,-0.67 -1.5,-1.5S11.17,8 12,8s1.5,0.67 1.5,1.5S12.83,11 12,11z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M21.99,4c0,-1.1 -0.89,-2 -1.99,-2H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h14l4,4 -0.01,-18z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:autoMirrored="true">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.2"
|
||||||
|
android:scaleY="1.2"
|
||||||
|
android:translateX="-2.4"
|
||||||
|
android:translateY="-1.8">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.0909091"
|
||||||
|
android:scaleY="1.0909091"
|
||||||
|
android:translateX="-1.0909091">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M9,21h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-2c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.58,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2zM9,9l4.34,-4.34L12,10h9v2l-3,7H9V9zM1,9h4v12H1z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.0909091"
|
||||||
|
android:scaleY="1.0909091"
|
||||||
|
android:translateX="-1.0909091">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M1,21h4L5,9L1,9v12zM23,10c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.59,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-2z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.2"
|
||||||
|
android:scaleY="1.2"
|
||||||
|
android:translateX="-2.4"
|
||||||
|
android:translateY="-2.4">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5,-5L11,7zM20,19h-8v2h8c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2h-8v2h8V19z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.5"
|
||||||
|
android:scaleY="1.5"
|
||||||
|
android:translateX="-6"
|
||||||
|
android:translateY="-6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.0909091"
|
||||||
|
android:scaleY="1.0909091"
|
||||||
|
android:translateX="-1.0909091"
|
||||||
|
android:translateY="-1.0909091">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM15,6c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4zM9,18c0.22,-0.72 3.31,-2 6,-2 2.7,0 5.8,1.29 6,2L9,18zM6,15v-3h3v-2L6,10L6,7L4,7v3L1,10v2h3v3z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.0909091"
|
||||||
|
android:scaleY="1.0909091"
|
||||||
|
android:translateX="-1.0909091"
|
||||||
|
android:translateY="-1.0909091">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:autoMirrored="true">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:autoMirrored="true">
|
||||||
|
<group android:scaleX="1.1428572"
|
||||||
|
android:scaleY="1.1428572"
|
||||||
|
android:translateX="-2.2857144"
|
||||||
|
android:translateY="-1.7142857">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<group android:scaleX="1.0909091"
|
||||||
|
android:scaleY="1.0909091"
|
||||||
|
android:translateX="-1.0909091"
|
||||||
|
android:translateY="-1.0909091">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M23,12l-2.44,-2.79l0.34,-3.69l-3.61,-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,12l2.44,2.79l-0.34,3.7l3.61,0.82L8.6,22.5l3.4,-1.47l3.4,1.46l1.89,-3.19l3.61,-0.82l-0.34,-3.69L23,12zM10.09,16.72l-3.8,-3.81l1.48,-1.48l2.32,2.33l5.85,-5.87l1.48,1.48L10.09,16.72z"/>
|
||||||
|
</group>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
|
||||||
|
</vector>
|
||||||
|
After Width: | Height: | Size: 196 B |
|
After Width: | Height: | Size: 314 B |
|
After Width: | Height: | Size: 657 B |
|
After Width: | Height: | Size: 270 B |
|
After Width: | Height: | Size: 236 B |
|
After Width: | Height: | Size: 256 B |
|
After Width: | Height: | Size: 181 B |
|
After Width: | Height: | Size: 182 B |
|
After Width: | Height: | Size: 329 B |
|
After Width: | Height: | Size: 433 B |
|
After Width: | Height: | Size: 381 B |
|
After Width: | Height: | Size: 318 B |
|
After Width: | Height: | Size: 153 B |
|
After Width: | Height: | Size: 373 B |
|
After Width: | Height: | Size: 472 B |
|
After Width: | Height: | Size: 399 B |
|
After Width: | Height: | Size: 292 B |
|
After Width: | Height: | Size: 443 B |
|
After Width: | Height: | Size: 423 B |
|
After Width: | Height: | Size: 491 B |
|
After Width: | Height: | Size: 539 B |
|
After Width: | Height: | Size: 398 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 233 B |
|
After Width: | Height: | Size: 413 B |
|
After Width: | Height: | Size: 169 B |
|
After Width: | Height: | Size: 205 B |
|
After Width: | Height: | Size: 181 B |
|
After Width: | Height: | Size: 146 B |
|
After Width: | Height: | Size: 144 B |
|
After Width: | Height: | Size: 263 B |
|
After Width: | Height: | Size: 320 B |
|
After Width: | Height: | Size: 283 B |
|
After Width: | Height: | Size: 248 B |
|
After Width: | Height: | Size: 122 B |
|
After Width: | Height: | Size: 278 B |
|
After Width: | Height: | Size: 370 B |
|
After Width: | Height: | Size: 333 B |
|
After Width: | Height: | Size: 189 B |
|
After Width: | Height: | Size: 278 B |
|
After Width: | Height: | Size: 262 B |
|
After Width: | Height: | Size: 300 B |
|
After Width: | Height: | Size: 343 B |
|
After Width: | Height: | Size: 297 B |
@@ -0,0 +1,30 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||||
|
<aapt:attr name="android:fillColor">
|
||||||
|
<gradient
|
||||||
|
android:endX="85.84757"
|
||||||
|
android:endY="92.4963"
|
||||||
|
android:startX="42.9492"
|
||||||
|
android:startY="49.59793"
|
||||||
|
android:type="linear">
|
||||||
|
<item
|
||||||
|
android:color="#44000000"
|
||||||
|
android:offset="0.0" />
|
||||||
|
<item
|
||||||
|
android:color="#00000000"
|
||||||
|
android:offset="1.0" />
|
||||||
|
</gradient>
|
||||||
|
</aapt:attr>
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
</vector>
|
||||||
|
After Width: | Height: | Size: 159 B |
|
After Width: | Height: | Size: 415 B |
|
After Width: | Height: | Size: 925 B |
|
After Width: | Height: | Size: 343 B |
|
After Width: | Height: | Size: 284 B |
|
After Width: | Height: | Size: 293 B |
|
After Width: | Height: | Size: 208 B |
|
After Width: | Height: | Size: 201 B |
|
After Width: | Height: | Size: 543 B |
|
After Width: | Height: | Size: 592 B |