Skip to content

Add a new feature #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dependencies {
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation "androidx.sharetarget:sharetarget:1.1.0"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-database:19.6.0'
implementation 'com.google.android.material:material:1.3.0'

compileOnly 'org.checkerframework:checker-qual:2.5.2'
compileOnly 'org.checkerframework:checker-compat-qual:2.5.0'
Expand Down
29 changes: 14 additions & 15 deletions TMessagesProj/google-services.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
{
"project_info": {
"project_number": "760348033671",
"firebase_url": "https://tmessages2.firebaseio.com",
"project_id": "tmessages2",
"storage_bucket": "tmessages2.appspot.com"
"project_number": "670560273254",
"project_id": "telegram-project-b3b4b",
"storage_bucket": "telegram-project-b3b4b.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:760348033671:android:dc022572c167a16c",
"mobilesdk_app_id": "1:670560273254:android:00d5193ff7609382f27ea7",
"android_client_info": {
"package_name": "org.telegram.messenger.beta"
"package_name": "org.telegram.messenger"
}
},
"oauth_client": [
{
"client_id": "760348033671-2hh8ebmuflsnjoc0kldkfells9rhtfni.apps.googleusercontent.com",
"client_id": "670560273254-u30uhjik5n0ahetlrecd3vh4453u6e38.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyA-t0jLPjUt2FxrA8VPK2EiYHcYcboIR6k"
"current_key": "AIzaSyCQWGruuGACZc7FbUmIevlNe9QWpamYn9g"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "760348033671-jiv412evc1r36rl4k7vhl1ba83atdmot.apps.googleusercontent.com",
"client_id": "670560273254-u30uhjik5n0ahetlrecd3vh4453u6e38.apps.googleusercontent.com",
"client_type": 3
}
]
Expand All @@ -37,27 +36,27 @@
},
{
"client_info": {
"mobilesdk_app_id": "1:760348033671:android:f6afd7b67eae3860",
"mobilesdk_app_id": "1:670560273254:android:5a96ff0a9588c28ef27ea7",
"android_client_info": {
"package_name": "org.telegram.messenger"
"package_name": "org.telegram.messenger.beta"
}
},
"oauth_client": [
{
"client_id": "760348033671-2hh8ebmuflsnjoc0kldkfells9rhtfni.apps.googleusercontent.com",
"client_id": "670560273254-u30uhjik5n0ahetlrecd3vh4453u6e38.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyA-t0jLPjUt2FxrA8VPK2EiYHcYcboIR6k"
"current_key": "AIzaSyCQWGruuGACZc7FbUmIevlNe9QWpamYn9g"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "760348033671-jiv412evc1r36rl4k7vhl1ba83atdmot.apps.googleusercontent.com",
"client_id": "670560273254-u30uhjik5n0ahetlrecd3vh4453u6e38.apps.googleusercontent.com",
"client_type": 3
}
]
Expand All @@ -66,4 +65,4 @@
}
],
"configuration_version": "1"
}
}
626 changes: 382 additions & 244 deletions TMessagesProj/src/main/AndroidManifest.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public class BuildVars {
LOGS_ENABLED = sharedPreferences.getBoolean("logsEnabled", DEBUG_VERSION);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.DrawerActionCell;
import org.telegram.ui.Cells.DividerCell;
import org.telegram.ui.Cells.DrawerActionCell;
import org.telegram.ui.Cells.DrawerAddCell;
import org.telegram.ui.Cells.DrawerProfileCell;
import org.telegram.ui.Cells.DrawerUserCell;
import org.telegram.ui.Cells.EmptyCell;
import org.telegram.ui.Cells.DrawerProfileCell;
import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.Components.SideMenultItemAnimator;

import java.util.ArrayList;
import java.util.Collections;

import androidx.recyclerview.widget.RecyclerView;

public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter {

private Context mContext;
Expand Down Expand Up @@ -247,6 +247,7 @@ private void resetItems() {
int inviteIcon;
int helpIcon;
int peopleNearbyIcon;
int myProductsIcon = R.drawable.products;
if (eventType == 0) {
newGroupIcon = R.drawable.menu_groups_ny;
//newSecretIcon = R.drawable.menu_secret_ny;
Expand Down Expand Up @@ -291,6 +292,7 @@ private void resetItems() {
inviteIcon = R.drawable.menu_invite;
helpIcon = R.drawable.menu_help;
peopleNearbyIcon = R.drawable.menu_nearby;
myProductsIcon = R.drawable.products;
}
items.add(new Item(2, LocaleController.getString("NewGroup", R.string.NewGroup), newGroupIcon));
//items.add(new Item(3, LocaleController.getString("NewSecretChat", R.string.NewSecretChat), newSecretIcon));
Expand All @@ -302,6 +304,7 @@ private void resetItems() {
}
items.add(new Item(11, LocaleController.getString("SavedMessages", R.string.SavedMessages), savedIcon));
items.add(new Item(8, LocaleController.getString("Settings", R.string.Settings), settingsIcon));
items.add(new Item(13, LocaleController.getString("Classified Advertising (Free) ", R.string.classified_advertising), myProductsIcon));
items.add(null); // divider
items.add(new Item(7, LocaleController.getString("InviteFriends", R.string.InviteFriends), inviteIcon));
items.add(new Item(9, LocaleController.getString("TelegramFAQ", R.string.TelegramFAQ), helpIcon));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
import org.telegram.ui.Components.ThemeEditorView;
import org.telegram.ui.Components.UpdateAppAlertDialog;
import org.telegram.ui.Components.voip.VoIPHelper;
import org.telegram.ui.products.MyProducts;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -578,6 +579,9 @@ public boolean drawChild(Canvas canvas, View child, long drawingTime) {
presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ENABLED));
}
drawerLayoutContainer.closeDrawer(false);
}else if(id == 13){
Intent myProductsIntent = new Intent(this, MyProducts.class);
startActivity(myProductsIntent);
}
}
});
Expand Down
117 changes: 117 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/products/AddProducts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.telegram.ui.products;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.UUID;

public class AddProducts extends Activity {


EditText edtDesc;
Button btnSave;
Spinner spinnerTitle;

// text data
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseProducts;

String title;


private int currentAccount = UserConfig.selectedAccount;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_products);

setTitle("Add a Product");

// text
firebaseDatabase = FirebaseDatabase.getInstance();
databaseProducts = firebaseDatabase.getReference("products");

edtDesc = findViewById(R.id.edt_desc);
btnSave = findViewById(R.id.btn_save_product);
spinnerTitle = findViewById(R.id.spinnerTitleType);
// spinnerTitle.setOnItemSelectedListener(this);
// ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
// android.R.layout.simple_spinner_item, R.array.title);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// spinnerTitle.setAdapter(adapter);

btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
saveDataToFirebase();
finish();
}
});


}

// @Override
// public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// title = (String) spinnerTitle.getSelectedItem();
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> adapterView) {
//
// }
private void saveDataToFirebase() {
//write a message to the database

String title = spinnerTitle.getSelectedItem().toString();
String desc = edtDesc.getText().toString().trim();

String idUser = String.valueOf(UserConfig.getInstance(currentAccount).getClientUserId());

if (!TextUtils.isEmpty(desc)) {
String id = databaseProducts.push().getKey();

Product product = new Product(id, title, desc, idUser);

databaseProducts.child(id).setValue(product);

Toast.makeText(this, "Product Advertise Added", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Product Advertise not Added", Toast.LENGTH_LONG).show();
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.telegram.ui.products;

import android.annotation.SuppressLint;
import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.appindexing.FirebaseUserActions;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;

import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.TLRPC;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;


public class MyProducts extends Activity {
private RecyclerView recyclerView;

// text data
private FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
private DatabaseReference root = firebaseDatabase.getReference().child("products");
Query query = root.child("products");


private ProductAdapter productAdapter;
private ArrayList<Product> productArrayList;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_products);

setTitle("Classified Advertising");

recyclerView = findViewById(R.id.recyclerview);

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);


productArrayList = new ArrayList<>();
productAdapter = new ProductAdapter(this, productArrayList);
recyclerView.setAdapter(productAdapter);

root.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
productArrayList.clear();
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
Product product = dataSnapshot.getValue(Product.class);
productArrayList.add(product);
}

productAdapter.notifyDataSetChanged();

}


@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent addProductIntent = new Intent(MyProducts.this, AddProducts.class);
startActivity(addProductIntent);
}
});
}

}
Loading