Skip to content

Commit

Permalink
Merge pull request #26 from shivshankar9/test-ai
Browse files Browse the repository at this point in the history
Test ai
  • Loading branch information
shivshankar9 authored Nov 19, 2024
2 parents 235ec17 + d739862 commit 1600aee
Show file tree
Hide file tree
Showing 18 changed files with 486 additions and 217 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions .idea/emulatorDisplays.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion app/src/main/java/com/bigdatanyze/ems1/AddPartyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class AddPartyActivity extends AppCompatActivity {

private EditText nameEditText;
private EditText contactEditText;
private EditText gstinEditText;
private EditText BillingAddressEditText;
private EditText ShippingAddressEditText;
private Button saveButton;
private PartyDao partyDao;

Expand All @@ -24,6 +27,9 @@ protected void onCreate(Bundle savedInstanceState) {

nameEditText = findViewById(R.id.editTextName);
contactEditText = findViewById(R.id.editTextContact);
gstinEditText= findViewById(R.id.editTextGstin);
BillingAddressEditText=findViewById(R.id.editTextBillingAddress);
ShippingAddressEditText=findViewById(R.id.editTextShippingAddress);
saveButton = findViewById(R.id.buttonSave);

partyDao = AppDatabase.getDatabase(this).partyDao();
Expand All @@ -34,13 +40,16 @@ protected void onCreate(Bundle savedInstanceState) {
private void saveParty() {
String name = nameEditText.getText().toString().trim();
String contact = contactEditText.getText().toString().trim();
String gstin= gstinEditText.getText().toString().trim();
String billing_address= BillingAddressEditText.toString().trim();
String shipping_address=ShippingAddressEditText.toString().trim();

if (name.isEmpty() || contact.isEmpty()) {
Toast.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT).show();
return;
}

Party party = new Party(name, contact);
Party party = new Party(name, contact,gstin,billing_address,shipping_address);
AppDatabase.databaseWriteExecutor.execute(() -> {
partyDao.insert(party);
runOnUiThread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ private void setupBottomNavigation() {
private List<String> getRecentActivities() {
return Arrays.asList("Added item A", "Removed item B", "Updated item C");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
Toast.makeText(this, "Image selection failed", Toast.LENGTH_SHORT).show();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public void onChanged(BusinessProfile businessProfile) {
if (businessProfile != null) {
businessName = businessProfile.getBusinessName();
businessAddress = businessProfile.getCompanyAddress();
businessCityStateZip = businessProfile.getEmail() + ", " + businessProfile.getEmail() + ", " + businessProfile.getEmail();
businessCityStateZip = businessProfile.getPhoneNumber() + ", " + businessProfile.getEmail() + ", " + businessProfile.getEmail();
businessEmail = businessProfile.getEmail();
businessPhone = "Phone: " + businessProfile.getPhoneNumber();
businessNameTextView.setText(businessProfile.getBusinessName()); // Update with business name }
}}
}}
});

// Set up button listeners
Expand All @@ -142,6 +142,7 @@ private void checkStoragePermissions() {
}
}


/**
* Generates the PDF of the invoice with improved layout and design.
*/
Expand Down Expand Up @@ -292,7 +293,6 @@ private void generatePdf() {
pdfDocument.close(); // Close the PDF document
}
}

/**
* Formats the file path to be more user-friendly.
*
Expand Down
140 changes: 75 additions & 65 deletions app/src/main/java/com/bigdatanyze/ems1/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.util.Log;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.bigdatanyze.ems1.databinding.ActivityMainBinding;
import com.bigdatanyze.ems1.model.BusinessProfile;
import com.bigdatanyze.ems1.viewmodel.BusinessProfileViewModel;
import com.bumptech.glide.Glide; // Add Glide import
import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity {

private ActivityMainBinding binding;
private BusinessProfileViewModel viewModel;
private static final int EDIT_PROFILE_REQUEST_CODE = 1; // Request code for edit profile
private static final int STORAGE_PERMISSION_CODE = 100;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -28,58 +39,46 @@ protected void onCreate(Bundle savedInstanceState) {
boolean isLoggedIn = preferences.getBoolean("isLoggedIn", false);

if (!isLoggedIn) {
// If not logged in, redirect to LoginActivity
// Redirect to LoginActivity if not logged in
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish(); // Finish MainActivity so the user cannot return to it
return; // Exit onCreate
finish();
return;
}

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

// Check and request storage permissions
checkStoragePermission();

// Initialize ViewModel
viewModel = new ViewModelProvider(this).get(BusinessProfileViewModel.class);

// Observe changes to the business profile
viewModel.getBusinessProfile().observe(this, profile -> {
if (profile != null) {
binding.tvHeading.setText(profile.getBusinessName()); // Update the business name

String logoUri = profile.getLogoUri();
Log.d("LogoUri", "Logo URI: " + logoUri);
if (logoUri != null && !logoUri.isEmpty()) {
// Use Glide to load the logo
Glide.with(this)
.load(Uri.parse(logoUri))
.placeholder(R.drawable.ic_logo) // Placeholder while loading
.error(R.drawable.ic_logo) // Default logo on error
.into(binding.logoImageView); // Target ImageView
} else {
binding.logoImageView.setImageResource(R.drawable.ic_logo); // Set a default logo if null or empty
}
binding.tvHeading.setText(profile.getBusinessName());
loadImage(profile.getLogoUri());
}
});

setupBottomNavigation();
setupHeaderIcons(); // Setup click listeners for icons and name/logo
setupHeaderIcons();
}

private void setupBottomNavigation() {
binding.bottomNavigationView.setOnItemSelectedListener(item -> {
Fragment selectedFragment = null;
int itemId = item.getItemId();

// Determine which fragment to load
if (itemId == R.id.nav_home) {
if (item.getItemId() == R.id.nav_home) {
selectedFragment = new HomeFragment();
} else if (itemId == R.id.nav_dashboard) {
} else if (item.getItemId() == R.id.nav_dashboard) {
selectedFragment = new DashboardFragment();
} else if (itemId == R.id.nav_menu) {
} else if (item.getItemId() == R.id.nav_menu) {
selectedFragment = new MenuFragment();
}

// Replace the fragment if one is selected
if (selectedFragment != null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, selectedFragment)
Expand All @@ -89,59 +88,70 @@ private void setupBottomNavigation() {
return true;
});

// Set default selection and load the default fragment
binding.bottomNavigationView.setSelectedItemId(R.id.nav_home);
}

private void setupHeaderIcons() {
// Settings icon click listener
binding.ivSettings.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(intent); // Redirect to SettingsActivity
});

// Notifications icon click listener
binding.ivNotifications.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, NotificationsActivity.class);
startActivity(intent); // Redirect to NotificationsActivity
});

// Profile icon click listener
binding.ivSettings.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, SettingsActivity.class)));
binding.ivNotifications.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, NotificationsActivity.class)));
binding.ivProfile.setOnClickListener(v -> openEditBusinessProfile());

// Logo click listener
binding.logoImageView.setOnClickListener(v -> openEditBusinessProfile());

// Name click listener
binding.tvHeading.setOnClickListener(v -> openEditBusinessProfile());
}

private void openEditBusinessProfile() {
Log.d("ProfileClick", "Edit Business Profile clicked");
Intent intent = new Intent(MainActivity.this, EditBusinessProfileActivity.class);
startActivityForResult(intent, EDIT_PROFILE_REQUEST_CODE); // Start for result
profileEditLauncher.launch(intent);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == EDIT_PROFILE_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
// Assuming the updated profile is sent back in the Intent
BusinessProfile updatedProfile = (BusinessProfile) data.getSerializableExtra("updatedProfile");
if (updatedProfile != null) {
binding.tvHeading.setText(updatedProfile.getBusinessName()); // Update the business name

String logoUri = updatedProfile.getLogoUri();
Log.d("LogoUri", "Updated Logo URI: " + logoUri);
if (logoUri != null && !logoUri.isEmpty()) {
Glide.with(this)
.load(Uri.parse(logoUri))
.placeholder(R.drawable.ic_logo) // Placeholder while loading
.error(R.drawable.ic_logo) // Default logo on error
.into(binding.logoImageView); // Target ImageView
} else {
binding.logoImageView.setImageResource(R.drawable.ic_logo); // Set a default logo if null or empty
private final ActivityResultLauncher<Intent> profileEditLauncher =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
BusinessProfile updatedProfile = (BusinessProfile) result.getData().getSerializableExtra("updatedProfile");
if (updatedProfile != null) {
binding.tvHeading.setText(updatedProfile.getBusinessName());
loadImage(updatedProfile.getLogoUri());
}
}
});

private void loadImage(String logoUri) {
if (logoUri != null && !logoUri.isEmpty()) {
Glide.with(this)
.load(Uri.parse(logoUri))
.placeholder(R.drawable.ic_logo)
.error(R.drawable.ic_logo)
.into(binding.logoImageView);
} else {
binding.logoImageView.setImageResource(R.drawable.ic_logo);
}
}

private void checkStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Android 11 and above: Check if Manage External Storage is granted
if (!Environment.isExternalStorageManager()) {
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivity(intent);
}
} else {
// Below Android 11: Request READ_EXTERNAL_STORAGE permission
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
}
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == STORAGE_PERMISSION_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("Permission", "Storage Permission Granted");
} else {
Log.d("Permission", "Storage Permission Denied");
}
}
}
Expand Down
Loading

0 comments on commit 1600aee

Please sign in to comment.